| 146 | } |
| 147 | |
| 148 | func TestSystem_ParentChild(t *testing.T) { |
| 149 | system := NewSystem("test") |
| 150 | defer system.Shutdown() |
| 151 | |
| 152 | // 创建父 Actor |
| 153 | parent := &ParentActor{} |
| 154 | parentPID := system.Spawn(parent, "parent") |
| 155 | |
| 156 | // 等待子 Actor 创建 |
| 157 | time.Sleep(100 * time.Millisecond) |
| 158 | |
| 159 | // 检查子 Actor 是否存在 |
| 160 | childPID, exists := system.GetActor("child-1") |
| 161 | assert.True(t, exists) |
| 162 | assert.NotNil(t, childPID) |
| 163 | |
| 164 | // 停止父 Actor 应该也停止子 Actor |
| 165 | system.Stop(parentPID) |
| 166 | time.Sleep(100 * time.Millisecond) |
| 167 | |
| 168 | _, exists = system.GetActor("child-1") |
| 169 | assert.False(t, exists) |
| 170 | } |
| 171 | |
| 172 | func TestSystem_SupervisorRestart(t *testing.T) { |
| 173 | config := DefaultSystemConfig() |