revid: added TestMultiSenderFailRetry test

Added test to check that if a sender is set to retry on send fails,
it will keep trying to send until it is successful, and have all
data that was intended to be written sent off.
This commit is contained in:
Saxon 2019-03-13 00:49:25 +10:30
parent e427836356
commit b8b26de901
1 changed files with 47 additions and 0 deletions

View File

@ -501,3 +501,50 @@ func TestMultiSenderFailNoRetry(t *testing.T) {
}
}
}
// TestMultiSenderFailRetry checks that a if a sender is set to retry on failed
// sends, that it does so repeatedly until it can successfully send.
func TestMultiSenderFailRetry(t *testing.T) {
// NB: This is only being tested with one sender - this is AusOcean's use case.
senders := []loadSender{newDummyLoadSender(false, true)}
ms, err := newMultiSender(senders, func() bool { return true })
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// Perform one write with successful send.
ms.Write([]byte{0x00})
// Now cause sender to fail on next write.
failedSender := ms.senders[0].(*dummyLoadSender)
failedSender.failOnSend = true
// Wrap next write in a routine. It will keep trying to send until we set
// failOnSend to false.
done := false
go func() {
ms.Write([]byte{0x01})
done = true
}()
// Now set failOnSend to false.
failedSender.mu.Lock()
failedSender.failOnSend = false
failedSender.mu.Unlock()
// Sleep and then check that we've successfully returned from the write.
time.Sleep(10 * time.Millisecond)
if done != true {
t.Fatal("did not exit write when send was successful")
}
// Write on last time.
ms.Write([]byte{0x02})
// Check that all the data is there.
got := failedSender.buf
want := [][]byte{{0x00}, {0x01}, {0x02}}
if !reflect.DeepEqual(got, want) {
t.Errorf("sender did not send expected data. \nGot: %v\nWant: %v\n", got, want)
}
}