mirror of https://bitbucket.org/ausocean/av.git
revid: added TestMultiSenderFailNoRetry
This commit is contained in:
parent
500edc05aa
commit
404190ca52
|
@ -31,6 +31,7 @@ package revid
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -300,6 +301,7 @@ func (s *dummyLoadSender) send() error {
|
|||
s.buf = append(s.buf, s.data)
|
||||
return nil
|
||||
}
|
||||
s.failHandled = false
|
||||
return errSendFailed
|
||||
}
|
||||
|
||||
|
@ -441,5 +443,62 @@ func TestMultiSenderNotActiveRetry(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestMultiSenderFailNoRetry checks that behaviour is as expected when a sender
|
||||
// fails at a send and does not retry.
|
||||
func TestMultiSenderFailNoRetry(t *testing.T) {
|
||||
senders := []loadSender{
|
||||
newDummyLoadSender(false, false),
|
||||
newDummyLoadSender(false, false),
|
||||
newDummyLoadSender(false, false),
|
||||
}
|
||||
|
||||
ms, err := newMultiSender(senders, func() bool { return true })
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
// We will perform two writes. We expect the second write not to be complete,
|
||||
// i.e. the senders should not send anything on this write.
|
||||
ms.Write([]byte{0x00})
|
||||
|
||||
// Make second sender fail a send.
|
||||
const failedSenderIdx = 1
|
||||
failedSender := ms.senders[failedSenderIdx].(*dummyLoadSender)
|
||||
failedSender.failOnSend = true
|
||||
ms.Write([]byte{0x01})
|
||||
|
||||
// Check that handleSendFail was called.
|
||||
if !failedSender.failHandled {
|
||||
t.Fatal("the failed send was not handled")
|
||||
}
|
||||
|
||||
// Now for next send we don't want to fail.
|
||||
failedSender.failOnSend = false
|
||||
ms.Write([]byte{0x02})
|
||||
|
||||
// Check number of slices sent for each sender and also check data.
|
||||
for i, sender := range ms.senders {
|
||||
// First check number of slices sent for each sender.
|
||||
wantLen := 3
|
||||
if i == failedSenderIdx {
|
||||
wantLen = 2
|
||||
}
|
||||
curSender := sender.(*dummyLoadSender)
|
||||
gotLen := len(curSender.buf)
|
||||
if gotLen != wantLen {
|
||||
t.Errorf("len of sender that failed is not expected: \nGot: %v\nWant: %v\n", gotLen, wantLen)
|
||||
}
|
||||
|
||||
// Now check the quality of the data.
|
||||
wantData := [][]byte{{0x00}, {0x01}, {0x02}}
|
||||
if i == failedSenderIdx {
|
||||
wantData = [][]byte{{0x00}, {0x02}}
|
||||
}
|
||||
gotData := curSender.buf
|
||||
if !reflect.DeepEqual(gotData, wantData) {
|
||||
t.Errorf("unexpect data sent through sender idx: %v. \nGot: %v\nWant: %v\n", i, gotData, wantData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test that send retry works
|
||||
// TODO: test that send fail works with no retry
|
||||
|
|
Loading…
Reference in New Issue