func TestDeadlockUnsynchronizedRead(t *testing.T) { endless := Zipper(p.Generator(), p.Generator()) out1, out2 := Unzipper(endless) <-out1 <-out2 <-out2 // expecting a read from out1, next pair is not unzipped yet // <-out2 // uncomment for deadlock }
func TestEndlessZipper(t *testing.T) { endless := Zipper(p.Generator(), p.Generator()) for i := 0; i < 1000; i++ { expected := PairInt{i, i} actual := <-endless if expected != actual { t.Errorf("%v != %v", expected, actual) } } }
func TestSecondChannelIndependency(t *testing.T) { endless := Zipper(p.Generator(), p.Generator()) _, out2 := Unzipper(endless) for expected := 0; expected < 200; expected++ { second := <-out2 if second != expected { t.Errorf("E: %d==%d", expected, second) } } }
func TestFirstChannelIndependency(t *testing.T) { endless := Zipper(p.Generator(), p.Generator()) out1, _ := Unzipper(endless) for expected := 0; expected < 200; expected++ { first := <-out1 if first != expected { t.Errorf("E: %d==%d", expected, first) } } }
func TestDeadlockInterruptedRead(t *testing.T) { endless := Zipper(p.Generator(), p.Generator()) out1, out2 := Unzipper(endless) // reading from both output channels initially for i := 0; i < 20; i++ { <-out1 <-out2 } // stop reading from `out1` (uncomment for deadlock) // for i := 0; i < 5; i++ { <-out2 } }
func TestUnzipper(t *testing.T) { endless := Zipper(p.Generator(), p.Generator()) out1, out2 := Unzipper(endless) for expected := 0; expected < 500; expected++ { first := <-out1 second := <-out2 if first != expected || second != expected { t.Errorf("E: %d==%d==%d", expected, first, second) } } // reading also works the other way around for i := 0; i < 5; i++ { <-out2 <-out1 } }