MCPcopy Create free account
hub / github.com/chainreactors/spray / TestRecordStat_ConcurrentSafety

Function TestRecordStat_ConcurrentSafety

core/runner_test.go:26–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestRecordStat_ConcurrentSafety(t *testing.T) {
27 r := &Runner{}
28
29 var wg sync.WaitGroup
30 for i := 0; i < 100; i++ {
31 wg.Add(1)
32 go func(n int) {
33 defer wg.Done()
34 r.recordStat(&pkg.Statistor{
35 Total: n,
36 ReqTotal: int32(n * 2),
37 FoundNumber: 1,
38 FailedNumber: 0,
39 })
40 }(i)
41 }
42
43 mustFinishCore(t, 5*time.Second, "concurrent recordStat deadlocked", func() {
44 wg.Wait()
45 })
46
47 stats := r.Stats()
48 if stats.Requests == 0 {
49 t.Fatal("stats.Requests should be > 0 after concurrent writes")
50 }
51}
52
53func TestRecordStat_NilStat(t *testing.T) {
54 r := &Runner{}

Callers

nothing calls this directly

Calls 4

recordStatMethod · 0.95
StatsMethod · 0.95
mustFinishCoreFunction · 0.85
DoneMethod · 0.45

Tested by

no test coverage detected