From 42bf44afdfe4914ef3b41f987cf27886aac73386 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 12 Mar 2019 18:08:43 +1030 Subject: [PATCH] revid: added test for multiSender to check active func function. Added a test to check that we correctly return from a write call if the multiSenders active callback func return false. --- revid/senders_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/revid/senders_test.go b/revid/senders_test.go index 360e540e..a6d1d298 100644 --- a/revid/senders_test.go +++ b/revid/senders_test.go @@ -346,6 +346,34 @@ func TestMultiSenderWrite(t *testing.T) { } } -// TODO: test that active func works +// TestMultiSenderNotActiveNoRetry checks that if the active func passed to +// newMultiSender returns false before a write, or in the middle of write with +// retries, then we return from Write as expected. +func TestMultiSenderNotActiveNoRetry(t *testing.T) { + senders := []loadSender{ + newDummyLoadSender(false), + newDummyLoadSender(false), + newDummyLoadSender(false), + } + active := true + activeFunc := func() bool { + return active + } + ms, err := newMultiSender(senders, false, activeFunc) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + ms.Write([]byte{0x00}) + active = false + ms.Write([]byte{0x01}) + + for _, dest := range ms.senders { + if len(dest.(*dummyLoadSender).buf) != 1 { + t.Errorf("length of sender buf is not 1 as expected") + } + } +} + // TODO: test that send retry works // TODO: test that send fail works with no retry