(t *testing.T)
| 541 | } |
| 542 | |
| 543 | func TestInMemoryService_Concurrency(t *testing.T) { |
| 544 | ctx := context.Background() |
| 545 | service := NewInMemoryService() |
| 546 | |
| 547 | sess, _ := service.Create(ctx, &CreateRequest{ |
| 548 | AppName: "test-app", |
| 549 | UserID: "user-1", |
| 550 | AgentID: "agent-1", |
| 551 | }) |
| 552 | |
| 553 | t.Run("并发追加事件", func(t *testing.T) { |
| 554 | done := make(chan bool) |
| 555 | numGoroutines := 10 |
| 556 | eventsPerGoroutine := 10 |
| 557 | |
| 558 | for i := range numGoroutines { |
| 559 | go func(id int) { |
| 560 | for j := range eventsPerGoroutine { |
| 561 | event := &Event{ |
| 562 | ID: "evt-concurrent-" + string(rune('0'+id)) + "-" + string(rune('0'+j)), |
| 563 | Timestamp: time.Now(), |
| 564 | InvocationID: "inv-1", |
| 565 | AgentID: "agent-1", |
| 566 | Branch: "root", |
| 567 | Author: "user", |
| 568 | } |
| 569 | if err := service.AppendEvent(ctx, sess.ID(), event); err != nil { |
| 570 | t.Errorf("AppendEvent failed: %v", err) |
| 571 | } |
| 572 | } |
| 573 | done <- true |
| 574 | }(i) |
| 575 | } |
| 576 | |
| 577 | // 等待所有 goroutine 完成 |
| 578 | for range numGoroutines { |
| 579 | <-done |
| 580 | } |
| 581 | |
| 582 | // 验证所有事件都已追加 |
| 583 | events, _ := service.GetEvents(ctx, sess.ID(), nil) |
| 584 | assert.Len(t, events, numGoroutines*eventsPerGoroutine) |
| 585 | }) |
| 586 | } |
| 587 | |
| 588 | func TestInMemoryService_StateScopes(t *testing.T) { |
| 589 | t.Skip("Skipping: inmemory service implementation has issues with state scopes") |
nothing calls this directly
no test coverage detected