Esempio n. 1
0
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
}
Esempio n. 2
0
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)
		}
	}
}
Esempio n. 3
0
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)
		}
	}
}
Esempio n. 4
0
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)
		}
	}
}
Esempio n. 5
0
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 }
}
Esempio n. 6
0
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
	}
}