Worker: fix sync issue in TestUpstreamBufferManagerUnavailable unit test
Fix synchronisation/goroutine issue in the "upstream buffer" test, where very occasionally the queue size was checked at the wrong time.
This commit is contained in:
parent
da1b42f9fa
commit
8af1b9d976
@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
@ -83,17 +84,20 @@ func TestUpstreamBufferManagerUnavailable(t *testing.T) {
|
||||
assert.Equal(t, 1, queueSize)
|
||||
|
||||
// Wait for the flushing with Manager available.
|
||||
resp := &api.TaskUpdateResponse{}
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
mocks.client.EXPECT().
|
||||
TaskUpdateWithResponse(ctx, taskID, update).
|
||||
Return(resp, nil).
|
||||
DoAndReturn(func(ctx context.Context, taskID string, body api.TaskUpdateJSONRequestBody, editors ...api.RequestEditorFn) (*api.TaskUpdateResponse, error) {
|
||||
wg.Done()
|
||||
return &api.TaskUpdateResponse{}, nil
|
||||
}).
|
||||
After(managerCallFail)
|
||||
|
||||
// Only add exactly the flush interval, as that maximises the chances of
|
||||
// getting conflicts on the database level (if we didn't have the
|
||||
// database-protection mutex).
|
||||
mocks.clock.Add(defaultUpstreamFlushInterval)
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// Queue should be empty now.
|
||||
ub.dbMutex.Lock()
|
||||
queueSize, err = ub.queueSize()
|
||||
|
Loading…
x
Reference in New Issue
Block a user