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

Function TestRoom_SendTo

pkg/core/room_test.go:347–404  ·  view source on GitHub ↗

TestRoom_SendTo 测试点对点消息

(t *testing.T)

Source from the content-addressed store, hash-verified

345
346// TestRoom_SendTo 测试点对点消息
347func TestRoom_SendTo(t *testing.T) {
348 deps := createTestDeps(t)
349 pool := NewPool(&PoolOptions{
350 Dependencies: deps,
351 MaxAgents: 10,
352 })
353 defer func() {
354 if err := pool.Shutdown(); err != nil {
355 t.Errorf("Shutdown failed: %v", err)
356 }
357 }()
358
359 room := NewRoom(pool)
360 ctx := context.Background()
361
362 // 创建 Agent
363 config1 := createTestConfig("agent-1")
364 _, err := pool.Create(ctx, config1)
365 if err != nil {
366 t.Fatalf("Failed to create agent-1: %v", err)
367 }
368
369 config2 := createTestConfig("agent-2")
370 _, err = pool.Create(ctx, config2)
371 if err != nil {
372 t.Fatalf("Failed to create agent-2: %v", err)
373 }
374
375 // 加入 Room
376 if err := room.Join("alice", "agent-1"); err != nil {
377 t.Fatalf("Failed to join room: %v", err)
378 }
379 if err := room.Join("bob", "agent-2"); err != nil {
380 t.Fatalf("Failed to join room: %v", err)
381 }
382
383 // 发送点对点消息
384 err = room.SendTo(ctx, "alice", "bob", "Private message")
385 if err != nil {
386 t.Fatalf("Failed to send private message: %v", err)
387 }
388
389 // 检查历史
390 history := room.GetHistory()
391 if len(history) != 1 {
392 t.Errorf("Expected 1 message in history, got %d", len(history))
393 }
394
395 if len(history) > 0 {
396 msg := history[0]
397 if msg.From != "alice" {
398 t.Errorf("Expected message from alice, got %s", msg.From)
399 }
400 if len(msg.To) != 1 || msg.To[0] != "bob" {
401 t.Errorf("Expected message to bob, got %v", msg.To)
402 }
403 }
404}

Callers

nothing calls this directly

Calls 9

ShutdownMethod · 0.95
CreateMethod · 0.95
JoinMethod · 0.95
SendToMethod · 0.95
GetHistoryMethod · 0.95
createTestDepsFunction · 0.85
NewPoolFunction · 0.85
NewRoomFunction · 0.85
createTestConfigFunction · 0.85

Tested by

no test coverage detected