From d7d00b6bba4ef978d76a2897aa24d8b87250014f Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 7 Jun 2023 19:02:32 +0200 Subject: [PATCH] minor fixes - message forwarding and test OK --- lib/action/action.go | 3 +++ lib/context/context.go | 11 ----------- lib/core/core.go | 3 +-- lib/lib.go | 2 -- tests/etc/etc.go | 2 +- tests/scopes_test.go | 6 ++++-- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/lib/action/action.go b/lib/action/action.go index a2efcf7..0a496fb 100644 --- a/lib/action/action.go +++ b/lib/action/action.go @@ -1,6 +1,8 @@ package action import ( + "fmt" + "git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib/message" ) @@ -38,6 +40,7 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action { } func match(ac lib.ActionConfig, msg lib.Message) bool { + fmt.Println("action.match", ac.Pattern(), msg.Action()) return ac.Pattern() == msg.Action() //return false } diff --git a/lib/context/context.go b/lib/context/context.go index dc4001e..5953b7c 100644 --- a/lib/context/context.go +++ b/lib/context/context.go @@ -2,7 +2,6 @@ package context import ( stdlib_context "context" - "fmt" "sync" "time" @@ -53,11 +52,6 @@ func (ctx *context) Mailbox() chan lib.Message { return ctx.mailbox } -func (ctx *context) HandleMsg(msg lib.Message) bool { - fmt.Println("context.HandleMsg ", msg) - return ctx.Config().MessageHandler()(ctx, msg) -} - func (ctx *context) WaitGroup() *sync.WaitGroup { return ctx.parent.WaitGroup() } @@ -78,11 +72,6 @@ func makeCtx(cfg lib.Config, parent Context) *context { } } -func HandleMsg(ctx lib.Context, msg lib.Message) bool { - fmt.Println("context.HandleMsg ", msg) - return ctx.Config().MessageHandler()(ctx, msg) -} - // implement interface context.Context from standard library func (ctx *context) Deadline() (deadline time.Time, ok bool) { diff --git a/lib/core/core.go b/lib/core/core.go index 51cdd88..5d2eed2 100644 --- a/lib/core/core.go +++ b/lib/core/core.go @@ -32,9 +32,8 @@ func Step(ctx lib.Context) (loop bool) { func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) { loop = true - fmt.Println("core.HandleMessage", msg) + fmt.Println("core.HandleMessage", ctx.Config().Name(), msg) for _, act := range action.Select(ctx, msg) { - //loop = act.Spec().Handler()(act) loop = act.Handle() } return diff --git a/lib/lib.go b/lib/lib.go index dfc60fe..a634c44 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -4,7 +4,6 @@ package lib import ( stdlib_context "context" - "fmt" "sync" ) @@ -80,7 +79,6 @@ func RunCtx(ctx Context, fct Proc) { } func HandleMsg(ctx Context, msg Message) bool { - fmt.Println("context.HandleMsg ", msg) return ctx.Config().MessageHandler()(ctx, msg) } diff --git a/tests/etc/etc.go b/tests/etc/etc.go index 3d119ee..d506881 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -29,7 +29,7 @@ func Config() lib.Config { cfg.Add(cfg_config) cfg_test_rcvr := b("test-receiver", core.Start) - cfg_test_rcvr.AddAction("*", action.BaseSpec(AH_Receiver, nil)) + cfg_test_rcvr.AddAction("demo", action.BaseSpec(AH_Receiver, nil)) cfg.Add(cfg_test_rcvr) return &cfg diff --git a/tests/scopes_test.go b/tests/scopes_test.go index 7c2fa92..ca0be64 100644 --- a/tests/scopes_test.go +++ b/tests/scopes_test.go @@ -1,6 +1,7 @@ package scopes_test import ( + "fmt" tbase "testing" "git.sr.ht/~cco/go-scopes/app" @@ -37,8 +38,8 @@ func SendTest(t *testing.T) { rcvr := message.SimpleAddress("testing") msg := message.StrMessage("demo") lib.Send(ctx, rcvr, msg) - rcvr = message.SimpleAddress("test-receiver") - lib.Send(ctx, rcvr, msg) + //rcvr = message.SimpleAddress("test-receiver") + //lib.Send(ctx, rcvr, msg) } // action handlers @@ -46,6 +47,7 @@ func SendTest(t *testing.T) { func Receiver(act lib.Action) bool { // t := testing.GetT(act.Context()) t := act.Context().Parent().State().(*testing.T) + fmt.Println("test.Receiver:", act.Message().Action()) t.AssertEqual(act.Message().Action(), "demo") return true }