(t *testing.T)
| 170 | } |
| 171 | |
| 172 | func 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 | |
| 205 | func TestSystem_ConcurrentMessages(t *testing.T) { |
| 206 | // 使用更大的邮箱配置 |
nothing calls this directly
no test coverage detected