| 42 | } |
| 43 | |
| 44 | func TestWait(t *testing.T) { |
| 45 | efd, err := Create() |
| 46 | if err != nil { |
| 47 | t.Fatalf("failed to Create(): %v", err) |
| 48 | } |
| 49 | defer efd.Close() |
| 50 | |
| 51 | // There's no way to test with certainty that Wait() blocks indefinitely, but |
| 52 | // as a best-effort we can wait a bit on it. |
| 53 | errCh := make(chan error) |
| 54 | go func() { |
| 55 | errCh <- efd.Wait() |
| 56 | }() |
| 57 | select { |
| 58 | case err := <-errCh: |
| 59 | t.Fatalf("Wait() returned without a call to Notify(): %v", err) |
| 60 | case <-time.After(500 * time.Millisecond): |
| 61 | } |
| 62 | |
| 63 | // Notify and check that Wait() returned. |
| 64 | if err := efd.Notify(); err != nil { |
| 65 | t.Fatalf("Notify() failed: %v", err) |
| 66 | } |
| 67 | select { |
| 68 | case err := <-errCh: |
| 69 | if err != nil { |
| 70 | t.Fatalf("Read() failed: %v", err) |
| 71 | } |
| 72 | case <-time.After(5 * time.Second): |
| 73 | t.Fatalf("Read() did not return after Notify()") |
| 74 | } |
| 75 | } |