Exemplo n.º 1
0
func doBenchmarkRPCData(b *testing.B, buffered bool) {
	b.StopTimer()
	plen := b.N * 1024          // N kB
	b.SetBytes(int64(plen) * 2) // both directions

	payload := string(vbytes.RandBytes(plen))

	inconn, outconn := vtesting.SelfConnection()
	ins, outs, err := MuxPairs(inconn, outconn, 2, buffered)
	if err != nil {
		b.Fatal("MuxPairs failed: ", err)
	}
	clients, err := SetupRPC(ins, outs)
	if err != nil {
		b.Fatal("SetupRPC failed: ", err)
	}
	rpayload1 := ""
	rpayload2 := ""
	retch := make(chan *rpc.Call, 2)
	b.StartTimer()
	clients[0].Go("RPCRecv.Echo", &payload, &rpayload1, retch)
	clients[1].Go("RPCRecv.Echo", &payload, &rpayload2, retch)
	<-retch
	<-retch
	b.StopTimer()
	if rpayload1 != payload || rpayload2 != payload {
		b.Fatal("Bigdata failed")
	}
}
Exemplo n.º 2
0
func TestStack(t *testing.T) {
	s := stack{}
	s.push(byte(123))
	if len(s) != 1 {
		t.Error("push failed")
	}
	if b, _ := s.pop(); b != byte(123) {
		t.Error("pop failed")
	}
	if len(s) != 0 {
		t.Error("post-pop len failed")
	}

	b := vbytes.RandBytes(1000)
	s.Write(b)
	if len(s) != len(b) {
		t.Error("post-write len failed")
	}
	for _, cb := range b {
		if b, _ := s.pop(); b != cb {
			t.Error("write failed")
		}
	}
	if len(s) != 0 {
		t.Error("post-read len failed")
	}

	s.Write(b)
	rs := make([]byte, len(b))
	s.Read(rs)
	if !vbytes.Equals(rs, b) {
		t.Error("readback failed")
	}
	if len(s) != 0 {
		t.Error("post-readback len failed")
	}

	s.push(byte(42))
	s.pop()
	if len(s) == cap(s) {
		t.Error("memory error")
	}
	s.compact()
	if len(s) != cap(s) {
		t.Error("compact error", len(s), "!=", cap(s))
	}
}
Exemplo n.º 3
0
func TestTape(t *testing.T) {
	t1 := tape{}
	if t1.Len() != 0 || t1.Ahead() != 0 || t1.Behind() != 0 {
		t.Error("initial state error")
	}
	_, err := t1.ReadByte()
	if err != EmptyErr {
		t.Error("failed to get EmptyErr")
	}
	n := 1000
	b := vbytes.RandBytes(n)
	t1.Write(b)
	if t1.Len() != n || t1.Ahead() != n || t1.Behind() != 0 {
		t.Error("post-write state error")
	}
	rb := make([]byte, n)
	t1.Read(rb)
	if !vbytes.Equals(rb, b) {
		t.Error("readback failed")
	}
	if t1.Len() != n || t1.Ahead() != 0 || t1.Behind() != n {
		t.Error("post-readback state error")
	}
	if t1.Advance(-2) != -2 {
		t.Error("advance error")
	}
	if t1.Len() != n || t1.Ahead() != 2 || t1.Behind() != n-2 {
		t.Error("post-advance state error")
	}
	t1.Read(rb[:1])
	if rb[0] != b[len(b)-2] {
		t.Error("post-advance post-readback error")
	}
	abyte, err := t1.ReadByte()
	if err != nil {
		t.Error("ReadByte() gave error:", err)
	}
	if abyte != b[len(b)-1] {
		t.Error("post-ReadByte error")
	}
}