fix: Avoid race condition in applier test

This commit is contained in:
Karl Isenberg 2022-04-21 18:15:28 -07:00
parent 1d43cea19f
commit db1ae2bbd1
1 changed files with 8 additions and 34 deletions

View File

@ -808,38 +808,12 @@ func TestApplier(t *testing.T) {
InventoryPolicy: inventory.PolicyMustMatch, InventoryPolicy: inventory.PolicyMustMatch,
EmitStatusEvents: true, EmitStatusEvents: true,
}, },
statusEvents: []pollevent.Event{ // There could be some status events for the existing Deployment,
{ // but we can't always expect to receive them before the applier
Type: pollevent.ResourceUpdateEvent, // exits, because the WaitTask is skipped when the ApplyTask errors.
Resource: &pollevent.ResourceStatus{ // So don't bother sending or expecting them.
Identifier: testutil.ToIdentifier(t, resources["deployment"]), statusEvents: []pollevent.Event{},
Status: status.InProgressStatus, expectedStatusEvents: []testutil.ExpEvent{},
},
},
{
Type: pollevent.ResourceUpdateEvent,
Resource: &pollevent.ResourceStatus{
Identifier: testutil.ToIdentifier(t, resources["deployment"]),
Status: status.CurrentStatus,
},
},
},
expectedStatusEvents: []testutil.ExpEvent{
{
EventType: event.StatusType,
StatusEvent: &testutil.ExpStatusEvent{
Identifier: testutil.ToIdentifier(t, resources["deployment"]),
Status: status.InProgressStatus,
},
},
{
EventType: event.StatusType,
StatusEvent: &testutil.ExpStatusEvent{
Identifier: testutil.ToIdentifier(t, resources["deployment"]),
Status: status.CurrentStatus,
},
},
},
expectedEvents: []testutil.ExpEvent{ expectedEvents: []testutil.ExpEvent{
{ {
EventType: event.InitType, EventType: event.InitType,
@ -1505,7 +1479,7 @@ func TestApplier(t *testing.T) {
var removed int var removed int
receivedEvents, removed = testutil.RemoveEqualEvents(receivedEvents, e) receivedEvents, removed = testutil.RemoveEqualEvents(receivedEvents, e)
if removed < 1 { if removed < 1 {
t.Fatalf("Expected status event not received: %#v", e.StatusEvent) t.Errorf("Expected status event not received: %#v", e.StatusEvent)
} }
} }
@ -1942,7 +1916,7 @@ func TestApplierCancel(t *testing.T) {
var removed int var removed int
receivedEvents, removed = testutil.RemoveEqualEvents(receivedEvents, e) receivedEvents, removed = testutil.RemoveEqualEvents(receivedEvents, e)
if removed < 1 { if removed < 1 {
t.Fatalf("Expected status event not received: %#v", e.StatusEvent) t.Errorf("Expected status event not received: %#v", e.StatusEvent)
} }
} }