MCPcopy
hub / github.com/EngoEngine/engo / TestMessageCounterWithRemoval

Function TestMessageCounterWithRemoval

message_test.go:33–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestMessageCounterWithRemoval(t *testing.T) {
34 mailbox := &MessageManager{}
35 msg := testMessageCounter{}
36 handlerID := mailbox.Listen("testMessageCounter", func(message Message) {
37 m, ok := message.(*testMessageCounter)
38 if !ok {
39 t.Error("Message should be of type testMessageCounter")
40 }
41 m.counter++
42 })
43 mailbox.Dispatch(&msg)
44 if msg.counter != 1 {
45 t.Error("Message should have been received 1 times by now")
46 }
47
48 mailbox.StopListen("testMessageCounter", handlerID)
49
50 mailbox.Dispatch(&msg)
51 if msg.counter != 1 {
52 t.Error("Message should have been received exactly 1 times since its handler was removed from listeners")
53 }
54}
55
56func TestMessageListenOnce(t *testing.T) {
57 mailbox := &MessageManager{}

Callers

nothing calls this directly

Calls 4

ListenMethod · 0.95
DispatchMethod · 0.95
StopListenMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected