MCPcopy
hub / github.com/docker/docker-agent / TestCompactionInputConcurrent

Function TestCompactionInputConcurrent

pkg/session/session_race_test.go:32–51  ·  view source on GitHub ↗

TestCompactionInputConcurrent pins the data-race fix for the compactor: CompactionInput must read s.Messages under s.mu (via snapshotItems) so it stays safe against concurrent AddMessage and ApplyCompaction calls. Run with -race; without the lock the slice header read aliases the live backing array

(t *testing.T)

Source from the content-addressed store, hash-verified

30// header read aliases the live backing array and the race detector
31// flags the AddMessage append.
32func TestCompactionInputConcurrent(t *testing.T) {
33 t.Parallel()
34
35 s := New()
36 var wg sync.WaitGroup
37 for range 100 {
38 wg.Go(func() {
39 s.AddMessage(&Message{Message: chat.Message{Role: chat.MessageRoleUser, Content: "u"}})
40 })
41 wg.Go(func() {
42 _, _ = s.CompactionInput()
43 })
44 }
45 // One concurrent ApplyCompaction-shaped write to exercise the same
46 // lock from a writer that also bumps the cumulative token counts.
47 wg.Go(func() {
48 s.ApplyCompaction(0, 0, Item{Summary: "snap"})
49 })
50 wg.Wait()
51}

Callers

nothing calls this directly

Calls 5

CompactionInputMethod · 0.80
ApplyCompactionMethod · 0.80
NewFunction · 0.70
AddMessageMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected