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

Function TestActorFunc

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

Source from the content-addressed store, hash-verified

332}
333
334func TestActorFunc(t *testing.T) {
335 system := NewSystem("test")
336 defer system.Shutdown()
337
338 received := make(chan Message, 1)
339
340 // 使用函数式 Actor
341 actorFunc := ActorFunc(func(ctx *Context, msg Message) {
342 if _, ok := msg.(*Started); ok {
343 return
344 }
345 received <- msg
346 })
347
348 pid := system.Spawn(actorFunc, "func-actor")
349 pid.Tell(&PingMsg{Count: 123})
350
351 select {
352 case msg := <-received:
353 ping, ok := msg.(*PingMsg)
354 require.True(t, ok)
355 assert.Equal(t, 123, ping.Count)
356 case <-time.After(time.Second):
357 t.Fatal("timeout")
358 }
359}
360
361// ============== 基准测试 ==============
362

Callers

nothing calls this directly

Calls 5

ShutdownMethod · 0.95
SpawnMethod · 0.95
NewSystemFunction · 0.85
ActorFuncFuncType · 0.85
TellMethod · 0.80

Tested by

no test coverage detected