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

Function TestSystem_SupervisorRestart

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

Source from the content-addressed store, hash-verified

170}
171
172func TestSystem_SupervisorRestart(t *testing.T) {
173 config := DefaultSystemConfig()
174 config.PanicHandler = func(actor *PID, msg Message, err any) {
175 // 静默处理 panic
176 }
177 system := NewSystemWithConfig("test", config)
178 defer system.Shutdown()
179
180 // 创建会 panic 的 Actor,使用监督策略
181 panicActor := &PanicActor{}
182 props := &Props{
183 Name: "panic-actor",
184 MailboxSize: 10,
185 SupervisorStrategy: NewOneForOneStrategy(5, time.Minute, DefaultDecider),
186 }
187 pid := system.SpawnWithProps(panicActor, props)
188
189 // 发送消息,触发 panic
190 system.Send(pid, &PingMsg{Count: 1})
191 time.Sleep(50 * time.Millisecond)
192
193 system.Send(pid, &PingMsg{Count: 2})
194 time.Sleep(50 * time.Millisecond)
195
196 // 第三次应该成功
197 system.Send(pid, &PingMsg{Count: 3})
198 time.Sleep(50 * time.Millisecond)
199
200 // Actor 应该仍然存在(被重启)
201 _, exists := system.GetActor("panic-actor")
202 assert.True(t, exists)
203}
204
205func TestSystem_ConcurrentMessages(t *testing.T) {
206 // 使用更大的邮箱配置

Callers

nothing calls this directly

Calls 7

DefaultSystemConfigFunction · 0.85
NewSystemWithConfigFunction · 0.85
NewOneForOneStrategyFunction · 0.85
GetActorMethod · 0.80
ShutdownMethod · 0.45
SpawnWithPropsMethod · 0.45
SendMethod · 0.45

Tested by

no test coverage detected