minor fixes - message forwarding and test OK

This commit is contained in:
Helmut Merz 2023-06-07 19:02:32 +02:00
parent 08263df110
commit d7d00b6bba
6 changed files with 9 additions and 18 deletions

View file

@ -1,6 +1,8 @@
package action package action
import ( import (
"fmt"
"git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/lib/message" "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 { func match(ac lib.ActionConfig, msg lib.Message) bool {
fmt.Println("action.match", ac.Pattern(), msg.Action())
return ac.Pattern() == msg.Action() return ac.Pattern() == msg.Action()
//return false //return false
} }

View file

@ -2,7 +2,6 @@ package context
import ( import (
stdlib_context "context" stdlib_context "context"
"fmt"
"sync" "sync"
"time" "time"
@ -53,11 +52,6 @@ func (ctx *context) Mailbox() chan lib.Message {
return ctx.mailbox 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 { func (ctx *context) WaitGroup() *sync.WaitGroup {
return ctx.parent.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 // implement interface context.Context from standard library
func (ctx *context) Deadline() (deadline time.Time, ok bool) { func (ctx *context) Deadline() (deadline time.Time, ok bool) {

View file

@ -32,9 +32,8 @@ func Step(ctx lib.Context) (loop bool) {
func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) { func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) {
loop = true loop = true
fmt.Println("core.HandleMessage", msg) fmt.Println("core.HandleMessage", ctx.Config().Name(), msg)
for _, act := range action.Select(ctx, msg) { for _, act := range action.Select(ctx, msg) {
//loop = act.Spec().Handler()(act)
loop = act.Handle() loop = act.Handle()
} }
return return

View file

@ -4,7 +4,6 @@ package lib
import ( import (
stdlib_context "context" stdlib_context "context"
"fmt"
"sync" "sync"
) )
@ -80,7 +79,6 @@ func RunCtx(ctx Context, fct Proc) {
} }
func HandleMsg(ctx Context, msg Message) bool { func HandleMsg(ctx Context, msg Message) bool {
fmt.Println("context.HandleMsg ", msg)
return ctx.Config().MessageHandler()(ctx, msg) return ctx.Config().MessageHandler()(ctx, msg)
} }

View file

@ -29,7 +29,7 @@ func Config() lib.Config {
cfg.Add(cfg_config) cfg.Add(cfg_config)
cfg_test_rcvr := b("test-receiver", core.Start) 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) cfg.Add(cfg_test_rcvr)
return &cfg return &cfg

View file

@ -1,6 +1,7 @@
package scopes_test package scopes_test
import ( import (
"fmt"
tbase "testing" tbase "testing"
"git.sr.ht/~cco/go-scopes/app" "git.sr.ht/~cco/go-scopes/app"
@ -37,8 +38,8 @@ func SendTest(t *testing.T) {
rcvr := message.SimpleAddress("testing") rcvr := message.SimpleAddress("testing")
msg := message.StrMessage("demo") msg := message.StrMessage("demo")
lib.Send(ctx, rcvr, msg) lib.Send(ctx, rcvr, msg)
rcvr = message.SimpleAddress("test-receiver") //rcvr = message.SimpleAddress("test-receiver")
lib.Send(ctx, rcvr, msg) //lib.Send(ctx, rcvr, msg)
} }
// action handlers // action handlers
@ -46,6 +47,7 @@ func SendTest(t *testing.T) {
func Receiver(act lib.Action) bool { func Receiver(act lib.Action) bool {
// t := testing.GetT(act.Context()) // t := testing.GetT(act.Context())
t := act.Context().Parent().State().(*testing.T) t := act.Context().Parent().State().(*testing.T)
fmt.Println("test.Receiver:", act.Message().Action())
t.AssertEqual(act.Message().Action(), "demo") t.AssertEqual(act.Message().Action(), "demo")
return true return true
} }