From 33f5df8f3597665e3a4615993ac4c27cd2c3e32b Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Wed, 12 May 2021 00:43:51 +0100 Subject: [PATCH] newreno exchange testing --- udp/congestion/newreno/exchange_test.go | 57 +++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 udp/congestion/newreno/exchange_test.go diff --git a/udp/congestion/newreno/exchange_test.go b/udp/congestion/newreno/exchange_test.go new file mode 100644 index 0000000..ae56355 --- /dev/null +++ b/udp/congestion/newreno/exchange_test.go @@ -0,0 +1,57 @@ +package newreno + +import ( + "context" + "encoding/binary" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" +) + +func TestNewReno_InitialHandle(t *testing.T) { + t.Run("InitialAckNackAreZero", func(t *testing.T) { + // ASSIGN + a := NewNewReno() + + ctx := context.Background() + + // ACT + initial, err := a.Initial(ctx) + + ack := binary.LittleEndian.Uint32(initial[0:4]) + nack := binary.LittleEndian.Uint32(initial[4:8]) + + // ASSERT + require.Nil(t, err) + + assert.Zero(t, ack) + assert.Zero(t, nack) + }) + + t.Run("InitialHandledWithAck", func(t *testing.T) { + // ASSIGN + a := NewNewReno() + b := NewNewReno() + + ctx := context.Background() + + // ACT + initial, err := a.Initial(ctx) + require.Nil(t, err) + + initialSeq := binary.LittleEndian.Uint32(initial[8:12]) + + response, data, err := b.Handle(ctx , initial) + + ack := binary.LittleEndian.Uint32(response[0:4]) + nack := binary.LittleEndian.Uint32(response[4:8]) + + // ASSERT + require.Nil(t, err) + + assert.Equal(t, initialSeq, ack) + assert.Zero(t, nack) + + assert.Nil(t, data) + }) +}