MCPcopy Index your code
hub / github.com/dagger/dagger / TestChangeCacheConcurrent

Function TestChangeCacheConcurrent

engine/filesync/change_cache_test.go:19–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17}
18
19func TestChangeCacheConcurrent(t *testing.T) {
20 t.Parallel()
21
22 ctx := t.Context()
23 c := newChangeCache()
24
25 var initCount atomic.Int32
26 initStarted := make(chan struct{})
27 initDone := make(chan struct{})
28
29 results := make([]*cachedChange, 0, 100)
30 var resultsMu sync.Mutex
31
32 var wg sync.WaitGroup
33 for range 100 {
34 wg.Add(1)
35 go func() {
36 defer wg.Done()
37 res, err := c.getOrInit(ctx, "42", func(_ context.Context) (*ChangeWithStat, error) {
38 if initCount.Add(1) == 1 {
39 close(initStarted)
40 }
41 <-initDone
42 return mkChange(ChangeKindModify), nil
43 })
44 assert.NilError(t, err)
45 assert.Equal(t, ChangeKindModify, res.result().kind)
46
47 resultsMu.Lock()
48 results = append(results, res)
49 resultsMu.Unlock()
50 }()
51 }
52
53 select {
54 case <-initStarted:
55 case <-time.After(5 * time.Second):
56 t.Fatal("timed out waiting for initializer")
57 }
58 close(initDone)
59
60 wg.Wait()
61 assert.Equal(t, int32(1), initCount.Load())
62
63 for _, res := range results {
64 res.release()
65 }
66}
67
68func TestChangeCacheErrors(t *testing.T) {
69 t.Parallel()

Callers

nothing calls this directly

Calls 13

newChangeCacheFunction · 0.85
closeFunction · 0.85
mkChangeFunction · 0.85
getOrInitMethod · 0.80
resultMethod · 0.80
ContextMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
EqualMethod · 0.65
WaitMethod · 0.65
LoadMethod · 0.65
AfterMethod · 0.45

Tested by

no test coverage detected