Esempio n. 1
0
func TestRecvInvalidPacket(t *testing.T) {
	q := new(vector.Vector)
	x := &net.UDPAddr{net.IP{1, 2, 3, 4}, 5}
	p := recvPacket(q, Packet{x, invalidProtobuf})
	assert.Equal(t, (*packet)(nil), p)
	assert.Equal(t, 0, q.Len())
}
Esempio n. 2
0
func TestRecvEmptyPacket(t *testing.T) {
	q := new(vector.Vector)
	x := &net.UDPAddr{net.IP{1, 2, 3, 4}, 5}

	p := recvPacket(q, Packet{x, []byte{}})
	assert.Equal(t, (*packet)(nil), p)
	assert.Equal(t, 0, q.Len())
}
Esempio n. 3
0
func avg(v *vector.Vector) (n int64) {
	t := time.Nanoseconds()
	if v.Len() == 0 {
		return -1
	}
	for _, x := range []interface{}(*v) {
		n += x.(trigger).t - t
	}
	return n / int64(v.Len())
}
Esempio n. 4
0
func TestRunSchedulesTick(t *testing.T) {
	var r run
	r.seqn = 1
	r.bound = 10
	r.out = make(chan Packet, 100)
	ticks := new(vector.Vector)

	r.update(&packet{msg: *newPropose("foo")}, -1, ticks)

	assert.Equal(t, 1, ticks.Len())
}
Esempio n. 5
0
func applyTriggers(packets, ticks *vector.Vector, now int64, tpl *msg) (n int) {
	for ticks.Len() > 0 {
		tt := ticks.At(0).(trigger)
		if tt.t > now {
			break
		}

		heap.Pop(ticks)

		p := new(packet)
		p.msg = *tpl
		p.msg.Seqn = &tt.n
		log.Println("applying", *p.Seqn, msg_Cmd_name[int32(*p.Cmd)])
		heap.Push(packets, p)
		n++
	}
	return
}
Esempio n. 6
0
func TestRecvPacket(t *testing.T) {
	q := new(vector.Vector)
	x := &net.UDPAddr{net.IP{1, 2, 3, 4}, 5}

	p := recvPacket(q, Packet{x, mustMarshal(&msg{
		Seqn: proto.Int64(1),
		Cmd:  invite,
	})})
	assert.Equal(t, &packet{x, msg{Seqn: proto.Int64(1), Cmd: invite}}, p)
	p = recvPacket(q, Packet{x, mustMarshal(&msg{
		Seqn: proto.Int64(2),
		Cmd:  invite,
	})})
	assert.Equal(t, &packet{x, msg{Seqn: proto.Int64(2), Cmd: invite}}, p)
	p = recvPacket(q, Packet{x, mustMarshal(&msg{
		Seqn: proto.Int64(3),
		Cmd:  invite,
	})})
	assert.Equal(t, &packet{x, msg{Seqn: proto.Int64(3), Cmd: invite}}, p)
	assert.Equal(t, 3, q.Len())
}
Esempio n. 7
0
func TestSchedTrigger(t *testing.T) {
	q := new(vector.Vector)
	d := int64(15e8)

	t0 := time.Nanoseconds()
	ts := t0 + d
	schedTrigger(q, 1, t0, d)

	assert.Equal(t, 1, q.Len())
	f, ok := q.At(0).(trigger)
	assert.Tf(t, ok, "expected a trigger, got a %T", q.At(0))
	assert.Equal(t, int64(1), f.n)
	assert.T(t, f.t == ts)
}