MCPcopy Create free account
hub / github.com/astercloud/aster / TestSystem_SpawnAndSend

Function TestSystem_SpawnAndSend

pkg/actor/actor_test.go:99–128  ·  view source on GitHub ↗

============== 测试用例 ==============

(t *testing.T)

Source from the content-addressed store, hash-verified

97// ============== 测试用例 ==============
98
99func TestSystem_SpawnAndSend(t *testing.T) {
100 system := NewSystem("test")
101 defer system.Shutdown()
102
103 // 创建计数器 Actor
104 counter := &CounterActor{}
105 pid := system.Spawn(counter, "counter")
106
107 assert.NotNil(t, pid)
108 assert.Equal(t, "counter", pid.ID)
109
110 // 发送消息
111 system.Send(pid, &CountMsg{Value: 10})
112 system.Send(pid, &CountMsg{Value: 20})
113 system.Send(pid, &CountMsg{Value: 30})
114
115 // 等待处理
116 time.Sleep(100 * time.Millisecond)
117
118 // 获取计数
119 replyCh := make(chan int, 1)
120 system.Send(pid, &GetCountMsg{ReplyTo: replyCh})
121
122 select {
123 case count := <-replyCh:
124 assert.Equal(t, 60, count)
125 case <-time.After(time.Second):
126 t.Fatal("timeout waiting for count")
127 }
128}
129
130func TestSystem_RequestResponse(t *testing.T) {
131 system := NewSystem("test")

Callers

nothing calls this directly

Calls 4

ShutdownMethod · 0.95
SpawnMethod · 0.95
SendMethod · 0.95
NewSystemFunction · 0.85

Tested by

no test coverage detected