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

Function TestInMemoryService_Concurrency

pkg/session/inmemory_test.go:543–586  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

541}
542
543func 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
588func TestInMemoryService_StateScopes(t *testing.T) {
589 t.Skip("Skipping: inmemory service implementation has issues with state scopes")

Callers

nothing calls this directly

Calls 7

CreateMethod · 0.95
AppendEventMethod · 0.95
GetEventsMethod · 0.95
NewInMemoryServiceFunction · 0.85
IDMethod · 0.65
LenMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected