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

Function TestSystem_ConcurrentMessages

pkg/actor/actor_test.go:205–248  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

203}
204
205func TestSystem_ConcurrentMessages(t *testing.T) {
206 // 使用更大的邮箱配置
207 config := DefaultSystemConfig()
208 config.MailboxSize = 50000
209 config.DefaultActorMailboxSize = 20000
210 system := NewSystemWithConfig("test", config)
211 defer system.Shutdown()
212
213 counter := &CounterActor{}
214 props := &Props{
215 Name: "counter",
216 MailboxSize: 20000,
217 }
218 pid := system.SpawnWithProps(counter, props)
219
220 // 并发发送消息
221 var wg sync.WaitGroup
222 numGoroutines := 100
223 messagesPerGoroutine := 100
224
225 for range numGoroutines {
226 wg.Add(1)
227 go func() {
228 defer wg.Done()
229 for range messagesPerGoroutine {
230 system.Send(pid, &CountMsg{Value: 1})
231 }
232 }()
233 }
234
235 wg.Wait()
236 time.Sleep(200 * time.Millisecond)
237
238 // 获取计数
239 replyCh := make(chan int, 1)
240 system.Send(pid, &GetCountMsg{ReplyTo: replyCh})
241
242 select {
243 case count := <-replyCh:
244 assert.Equal(t, numGoroutines*messagesPerGoroutine, count)
245 case <-time.After(time.Second):
246 t.Fatal("timeout waiting for count")
247 }
248}
249
250func TestSystem_Stop(t *testing.T) {
251 system := NewSystem("test")

Callers

nothing calls this directly

Calls 7

DefaultSystemConfigFunction · 0.85
NewSystemWithConfigFunction · 0.85
WaitMethod · 0.80
AddMethod · 0.65
ShutdownMethod · 0.45
SpawnWithPropsMethod · 0.45
SendMethod · 0.45

Tested by

no test coverage detected