From e4278363560ea5491a88aab5583e72e8a7440ec7 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 12 Mar 2019 23:55:18 +1030 Subject: [PATCH] revid: removed closure for accessing active flag we only need to set the active flag once, so there's no need for a closure here. --- revid/senders_test.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/revid/senders_test.go b/revid/senders_test.go index d88a4f19..215b5a20 100644 --- a/revid/senders_test.go +++ b/revid/senders_test.go @@ -280,6 +280,7 @@ type dummyLoadSender struct { failOnSend bool failHandled bool retry bool + mu sync.Mutex } // newDummyLoadSender returns a pointer to a new dummyLoadSender. @@ -297,7 +298,7 @@ func (s *dummyLoadSender) load(d []byte) error { // If failOnSend is set to true, we expect that data sent won't be written to // the buf simulating a failed send. func (s *dummyLoadSender) send() error { - if !s.failOnSend { + if !s.getFailOnSend() { s.buf = append(s.buf, s.data) return nil } @@ -305,6 +306,12 @@ func (s *dummyLoadSender) send() error { return errSendFailed } +func (s *dummyLoadSender) getFailOnSend() bool { + s.mu.Lock() + defer s.mu.Unlock() + return s.failOnSend +} + // release sets dummyLoadSender's data slice to nil. data can be checked to see // if release has been called at the right time. func (s *dummyLoadSender) release() { @@ -402,14 +409,6 @@ func TestMultiSenderNotActiveRetry(t *testing.T) { // We will run the ms.Write as routine so we need some sync. var mu sync.Mutex - // After the write is running as a routine we will call this to change the - // running state of the 'owner'. - setActive := func(b bool) { - mu.Lock() - defer mu.Unlock() - active = b - } - // Once we use setActive to change the state of the fake owner, this will // return false and we expect the ms.Write method to return from the continous // send retry state. @@ -434,7 +433,9 @@ func TestMultiSenderNotActiveRetry(t *testing.T) { // Wait for half a second and then change the active state. time.Sleep(500 * time.Millisecond) - setActive(false) + mu.Lock() + active = false + mu.Unlock() // Wait half a second for the routine to return and check that done is true. time.Sleep(500 * time.Millisecond) @@ -500,5 +501,3 @@ func TestMultiSenderFailNoRetry(t *testing.T) { } } } - -// TODO: test that send retry works