(t *testing.T)
| 24 | } |
| 25 | |
| 26 | func 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 | |
| 53 | func TestRecordStat_NilStat(t *testing.T) { |
| 54 | r := &Runner{} |
nothing calls this directly
no test coverage detected