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

Method TestBroadcast

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

Source from the content-addressed store, hash-verified

170}
171
172func (s *ActorSuite) TestBroadcast() {
173 // 创建订阅者
174 numSubscribers := 5
175 subscribers := make([]*actor.PID, numSubscribers)
176 actorInstances := make([]*SubscriberActor, numSubscribers)
177
178 for i := range numSubscribers {
179 name := fmt.Sprintf("sub-%d", i)
180 sub := &SubscriberActor{name: name}
181 actorInstances[i] = sub
182 subscribers[i] = s.system.Spawn(sub, name)
183 }
184
185 time.Sleep(50 * time.Millisecond)
186
187 // 广播消息
188 messages := []string{"msg1", "msg2", "msg3"}
189 for _, content := range messages {
190 for _, pid := range subscribers {
191 pid.Tell(&BroadcastMsg{Content: content})
192 }
193 }
194
195 time.Sleep(100 * time.Millisecond)
196
197 // 验证每个订阅者都收到了所有消息
198 for i, sub := range actorInstances {
199 sub.mu.Lock()
200 count := len(sub.received)
201 sub.mu.Unlock()
202 s.Equal(len(messages), count,
203 "订阅者 %d 应收到 %d 条消息", i, len(messages))
204 }
205}
206
207func (s *ActorSuite) TestActorStats() {
208 // 创建多个 Actor

Callers

nothing calls this directly

Calls 2

TellMethod · 0.80
SpawnMethod · 0.45

Tested by

no test coverage detected