From 576a7bbd4138bfce7ad1e9d4a2853f3fbd972d2b Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 19 Oct 2021 16:38:31 +0800 Subject: [PATCH] test(middle): add test worker --- pkg/middle/worker_test.go | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/pkg/middle/worker_test.go b/pkg/middle/worker_test.go index df94f50..1db20bf 100644 --- a/pkg/middle/worker_test.go +++ b/pkg/middle/worker_test.go @@ -2,30 +2,41 @@ package middle import ( "context" + "fmt" "testing" "time" "gitee.com/timedb/wheatCache/pkg/event" middleMsg "gitee.com/timedb/wheatCache/pkg/middle-msg" - "github.com/stretchr/testify/require" ) -func Test_middleware_driver(t *testing.T) { - ctx := context.Background() - middleware := NewMiddleWare() - require.Equal(t, middleware.plugins["logcontext"][0].Name(), "logMiddle") - event := event.NewEvent("logcontext") - event.SetValue(middleMsg.MiddleMsgKey, "123") - middleware.eventProduce.Call(ctx, event) - require.Equal(t, middleware.consumerCount, 5) - time.Sleep(1 * time.Second) +func Test_middleware_loadPlugins(t *testing.T) { + m := NewMiddleWare() + m.loadPlugins() + + fmt.Println(m.plugins) } func TestWorker(t *testing.T) { - // ctx := context.Background() - event := event.NewEvent("logcontext") - + ctx := context.Background() m := NewMiddleWare() - m.eventDriver.Put(event) + product := event.NewProduce(m.GetEventDriver()) + middleMsg.SendMiddleMsg(ctx, product, &middleMsg.LogContext{ + Msg: "debug msg", + }) + + middleMsg.SendMiddleMsg(ctx, product, &middleMsg.PulginsInfos{ + Infos: []*middleMsg.PulginsInfo{ + { + Desc: "miss", + }, + }, + }) + + middleMsg.SendMiddleMsg(ctx, product, &middleMsg.LruTTlContext{ + Keys: []string{"1", "2", "3"}, + }) + + time.Sleep(1 * time.Second) }