MCPcopy Create free account
hub / github.com/cloud-native-go/examples / TestDebounceFirstDataRace

Function TestDebounceFirstDataRace

ch04/debounce_first_test.go:27–66  ·  view source on GitHub ↗

TestDebounceFirstDataRace tests for data races.

(t *testing.T)

Source from the content-addressed store, hash-verified

25
26// TestDebounceFirstDataRace tests for data races.
27func TestDebounceFirstDataRace(t *testing.T) {
28 ctx := context.Background()
29
30 circuit := failAfter(1)
31 debounce := DebounceFirst(circuit, time.Second)
32
33 wg := sync.WaitGroup{}
34
35 for count := 1; count <= 10; count++ {
36 wg.Add(1)
37
38 go func(count int) {
39 defer wg.Done()
40
41 time.Sleep(50 * time.Millisecond)
42
43 _, err := debounce(ctx)
44
45 t.Logf("attempt %d: err=%v", count, err)
46 }(count)
47 }
48
49 time.Sleep(time.Second * 2)
50
51 for count := 1; count <= 10; count++ {
52 wg.Add(1)
53
54 go func(count int) {
55 defer wg.Done()
56
57 time.Sleep(50 * time.Millisecond)
58
59 _, err := debounce(ctx)
60
61 t.Logf("attempt %d: err=%v", count, err)
62 }(count)
63 }
64
65 wg.Wait()
66}

Callers

nothing calls this directly

Calls 3

failAfterFunction · 0.85
DebounceFirstFunction · 0.85
WaitMethod · 0.65

Tested by

no test coverage detected