(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func Test_Execute(t *testing.T) { |
| 11 | executeOnce := once{} |
| 12 | execution := make(chan struct{}) |
| 13 | fExecute := func() { |
| 14 | execution <- struct{}{} |
| 15 | } |
| 16 | go executeOnce.Do(fExecute) |
| 17 | go executeOnce.Do(fExecute) |
| 18 | |
| 19 | select { |
| 20 | case <-execution: |
| 21 | // expected |
| 22 | case <-time.After(100 * time.Millisecond): |
| 23 | t.Fatal("fExecute should be executed once") |
| 24 | } |
| 25 | |
| 26 | select { |
| 27 | case <-execution: |
| 28 | t.Fatal("should only execute once") |
| 29 | case <-time.After(100 * time.Millisecond): |
| 30 | // expected |
| 31 | } |
| 32 | |
| 33 | assert.False(t, executeOnce.mayExecute()) |
| 34 | |
| 35 | go executeOnce.Do(fExecute) |
| 36 | |
| 37 | select { |
| 38 | case <-execution: |
| 39 | t.Fatal("should only execute once") |
| 40 | case <-time.After(100 * time.Millisecond): |
| 41 | // expected |
| 42 | } |
| 43 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…