rtt finding test
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jake Hillion 2021-02-27 14:01:17 +00:00
parent ce211bb142
commit a2bb734d8d

View File

@ -45,12 +45,12 @@ func (n *newRenoTest) Start(ctx context.Context) {
return
case p := <-n.aOutbound:
// deliver the packet at least half an halfRtt in the future (non-deterministic)
time.AfterFunc(n.halfRtt/2, func() {
time.AfterFunc(n.halfRtt, func() {
n.bInbound <- p
})
case p := <-n.bOutbound:
// deliver the packet at least half an halfRtt in the future (non-deterministic)
time.AfterFunc(n.halfRtt/2, func() {
time.AfterFunc(n.halfRtt, func() {
n.aInbound <- p
})
}
@ -127,6 +127,7 @@ func TestNewReno_Congestion(t *testing.T) {
t.Run("Lossless", func(t *testing.T) {
// ASSIGN
rtt := 80 * time.Millisecond
numPackets := 50
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -137,7 +138,7 @@ func TestNewReno_Congestion(t *testing.T) {
c.RunSideB(ctx)
// ACT
for i := 0; i < 50; i++ {
for i := 0; i < numPackets; i++ {
// sleep to simulate preparing packet
time.Sleep(1 * time.Millisecond)
seq := c.sideA.Sequence()
@ -150,7 +151,7 @@ func TestNewReno_Congestion(t *testing.T) {
}
// allow the systems to catch up before asserting
time.Sleep(30 * time.Millisecond)
time.Sleep(rtt + 30*time.Millisecond)
// ASSERT
@ -158,7 +159,72 @@ func TestNewReno_Congestion(t *testing.T) {
assert.Equal(t, uint32(0), c.sideA.ack)
assert.Equal(t, uint32(0), c.sideB.nack)
assert.Equal(t, uint32(50), c.sideB.ack)
assert.Equal(t, uint32(numPackets), c.sideB.ack)
})
})
t.Run("TwoWay", func(t *testing.T) {
t.Run("PredictsRtt", func(t *testing.T) {
// ASSIGN
rtt := 160 * time.Millisecond
numPackets := 100
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := newNewRenoTest(rtt)
c.Start(ctx)
c.RunSideA(ctx)
c.RunSideB(ctx)
// ACT
done := make(chan struct{})
go func() {
for i := 0; i < numPackets; i++ {
time.Sleep(1 * time.Millisecond)
seq := c.sideA.Sequence()
c.aOutbound <- congestionPacket{
seq: seq,
nack: c.sideA.NextNack(),
ack: c.sideA.NextAck(),
}
}
done <- struct{}{}
}()
go func() {
for i := 0; i < numPackets; i++ {
time.Sleep(1 * time.Millisecond)
seq := c.sideB.Sequence()
c.bOutbound <- congestionPacket{
seq: seq,
nack: c.sideB.NextNack(),
ack: c.sideB.NextAck(),
}
}
done <- struct{}{}
}()
<-done
<-done
time.Sleep(rtt + 30*time.Millisecond)
// ASSERT
assert.Equal(t, uint32(0), c.sideA.nack)
assert.Equal(t, uint32(numPackets), c.sideA.ack)
assert.Equal(t, uint32(0), c.sideB.nack)
assert.Equal(t, uint32(numPackets), c.sideB.ack)
assert.InDelta(t, float64(rtt.Nanoseconds()), c.sideA.rttNanos, float64(8*time.Millisecond.Nanoseconds()))
assert.InDelta(t, float64(rtt.Nanoseconds()), c.sideB.rttNanos, float64(8*time.Millisecond.Nanoseconds()))
})
})
}