Ensure there are no data races
(t *testing.T)
| 2409 | |
| 2410 | // Ensure there are no data races |
| 2411 | func TestDiffRace(t *testing.T) { |
| 2412 | t.Parallel() |
| 2413 | |
| 2414 | expected := map[string]string{ |
| 2415 | "a": "A", |
| 2416 | "b": "B", |
| 2417 | "c": "C", |
| 2418 | } |
| 2419 | |
| 2420 | actual := map[string]string{ |
| 2421 | "d": "D", |
| 2422 | "e": "E", |
| 2423 | "f": "F", |
| 2424 | } |
| 2425 | |
| 2426 | // run diffs in parallel simulating tests with t.Parallel() |
| 2427 | numRoutines := 10 |
| 2428 | rChans := make([]chan string, numRoutines) |
| 2429 | for idx := range rChans { |
| 2430 | rChans[idx] = make(chan string) |
| 2431 | go func(ch chan string) { |
| 2432 | defer close(ch) |
| 2433 | ch <- diff(expected, actual) |
| 2434 | }(rChans[idx]) |
| 2435 | } |
| 2436 | |
| 2437 | for _, ch := range rChans { |
| 2438 | for msg := range ch { |
| 2439 | NotZero(t, msg) // dummy assert |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | type mockTestingT struct { |
| 2445 | errorFmt string |