1package nbc 2 3import ( 4 "github.com/hectane/go-attest" 5 6 "testing" 7 "time" 8) 9 10// Because there is no synchronization between the testing goroutine and the 11// channel's goroutine, a small delay must be introduced between operations. 12func pause() { 13 <-time.After(50 * time.Millisecond) 14} 15 16func TestNonBlockingChan(t *testing.T) { 17 n := New() 18 pause() 19 if err := attest.ChanSend(n.Send, true); err != nil { 20 t.Fatal(err) 21 } 22 pause() 23 l := n.Len() 24 if l != 1 { 25 t.Fatalf("%d != 1", 1) 26 } 27 i, err := attest.ChanRecv(n.Recv) 28 if err != nil { 29 t.Fatal(err) 30 } 31 if i != true { 32 t.Fatalf("%v != true", i) 33 } 34 pause() 35 l = n.Len() 36 if l != 0 { 37 t.Fatalf("%d != 0", 0) 38 } 39 close(n.Send) 40 pause() 41 if err := attest.ChanClosed(n.Recv); err != nil { 42 t.Fatal(err) 43 } 44} 45