mirror of https://bitbucket.org/ausocean/av.git
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.
This commit is contained in:
parent
404190ca52
commit
e427836356
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue