Exemplo n.º 1
0
func NewRandomUnreliableTransport(f trace.Frame, nok, ndrop int, expa, expb time.Duration) *Transport {
	return NewTransport(f, func(f0, f1 trace.Frame, a0, a1 net.Addr) (net.Conn, net.Conn) {
		nok, ndrop := rand.Intn(nok+1), rand.Intn(ndrop+1)
		nok = max(nok, 1)
		f.Printf("TRANSPORT PROFILE NOK=%d, NDROP=%d", nok, ndrop)
		return NewSievePipe(f0, f1, a0, a1, nok, ndrop, expa, expb)
	})
}
func testWrite(fr trace.Frame, t *testing.T, c *Conn, ready chan<- int) {
	defer func() {
		ready <- 1
	}()
	for i := 0; i < N; i++ {
		if err := c.Write([]byte{byte(i), byte(i + 1), byte(i + 2)}); err != nil {
			t.Errorf("write (%s)", err)
			failNow()
		}
		fr.Printf("WROTE %d/%d", i+1, N)
	}
	if err := c.Close(); err != nil {
		t.Fatalf("write-side close (%s)", err)
		failNow()
	}
	fr.Printf("CLOSED WRITE")
}
func testRead(fr trace.Frame, t *testing.T, c *Conn, ready chan<- int) {
	defer func() {
		ready <- 1
	}()
	for i := 0; i < N; i++ {
		q, err := c.Read()
		if err != nil {
			t.Fatalf("read (%s)", err)
			failNow()
		}
		z := []byte{byte(i), byte(i + 1), byte(i + 2)}
		if !reflect.DeepEqual(q, z) {
			t.Fatalf("expecting %#v, got %#v", z, q)
			failNow()
		}
		fr.Printf("READ %d/%d", i+1, N)
	}
	if err := c.Close(); err != nil {
		t.Fatalf("read-side close (%s)", err)
		failNow()
	}
	fr.Printf("CLOSED READ")
}
Exemplo n.º 4
0
func NewUnreliableTransport(f trace.Frame, nok, ndrop int, expa, expb time.Duration) *Transport {
	return NewTransport(f, func(f0, f1 trace.Frame, a0, a1 net.Addr) (net.Conn, net.Conn) {
		f.Printf("TRANSPORT PROFILE NOK=%d, NDROP=%d", nok, ndrop)
		return NewSievePipe(f0, f1, a0, a1, nok, ndrop, expa, expb)
	})
}