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

Method TestSupervisorRestart

examples/actor/actor_test.go:106–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104}
105
106func (s *ActorSuite) TestSupervisorRestart() {
107 // 使用静默 panic 处理器
108 config := actor.DefaultSystemConfig()
109 config.PanicHandler = func(a *actor.PID, msg actor.Message, err any) {}
110 s.system.Shutdown()
111 s.system = actor.NewSystemWithConfig("test", config)
112
113 // 创建不稳定的 Actor(会失败 2 次)
114 unstable := &UnstableActor{name: "unstable", maxFails: 2}
115 props := &actor.Props{
116 Name: "unstable",
117 MailboxSize: 100,
118 SupervisorStrategy: actor.NewOneForOneStrategy(5, time.Minute, actor.DefaultDecider),
119 }
120 pid := s.system.SpawnWithProps(unstable, props)
121
122 // 第一次请求会触发 panic
123 _, err := pid.Request(&PingMsg{Count: 1}, 500*time.Millisecond)
124 s.Error(err, "第一次请求应超时(Actor panic)")
125
126 time.Sleep(100 * time.Millisecond)
127
128 // 第二次请求也会触发 panic
129 _, err = pid.Request(&PingMsg{Count: 2}, 500*time.Millisecond)
130 s.Error(err, "第二次请求应超时(Actor panic)")
131
132 time.Sleep(100 * time.Millisecond)
133
134 // 第三次请求应该成功(Actor 已恢复)
135 resp, err := pid.Request(&PingMsg{Count: 3}, time.Second)
136 s.Require().NoError(err, "第三次请求应成功")
137
138 pong, ok := resp.(*PongMsg)
139 s.Require().True(ok, "响应应为 PongMsg")
140 s.Equal(3, pong.Count, "计数应匹配")
141}
142
143func (s *ActorSuite) TestPipeline() {
144 // 创建 3 阶段流水线

Callers

nothing calls this directly

Calls 7

DefaultSystemConfigFunction · 0.92
NewSystemWithConfigFunction · 0.92
NewOneForOneStrategyFunction · 0.92
ErrorMethod · 0.65
ShutdownMethod · 0.45
SpawnWithPropsMethod · 0.45
RequestMethod · 0.45

Tested by

no test coverage detected