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"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/benbjohnson/clock"
|
"github.com/benbjohnson/clock"
|
||||||
@ -83,17 +84,20 @@ func TestUpstreamBufferManagerUnavailable(t *testing.T) {
|
|||||||
assert.Equal(t, 1, queueSize)
|
assert.Equal(t, 1, queueSize)
|
||||||
|
|
||||||
// Wait for the flushing with Manager available.
|
// Wait for the flushing with Manager available.
|
||||||
resp := &api.TaskUpdateResponse{}
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(1)
|
||||||
mocks.client.EXPECT().
|
mocks.client.EXPECT().
|
||||||
TaskUpdateWithResponse(ctx, taskID, update).
|
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)
|
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)
|
mocks.clock.Add(defaultUpstreamFlushInterval)
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
// Queue should be empty now.
|
// Queue should be empty now.
|
||||||
ub.dbMutex.Lock()
|
ub.dbMutex.Lock()
|
||||||
queueSize, err = ub.queueSize()
|
queueSize, err = ub.queueSize()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user