Skip to content

Commit

Permalink
Merge pull request #582 from karlkfi/karl-fix-flaky-applier-test
Browse files Browse the repository at this point in the history
fix: Avoid race condition in applier test
  • Loading branch information
k8s-ci-robot committed Apr 22, 2022
2 parents 1fead05 + db1ae2b commit 2ae0f05
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions pkg/apply/applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,38 +808,12 @@ func TestApplier(t *testing.T) {
InventoryPolicy: inventory.PolicyMustMatch,
EmitStatusEvents: true,
},
statusEvents: []pollevent.Event{
{
Type: pollevent.ResourceUpdateEvent,
Resource: &pollevent.ResourceStatus{
Identifier: testutil.ToIdentifier(t, resources["deployment"]),
Status: status.InProgressStatus,
},
},
{
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,
},
},
},
// There could be some status events for the existing Deployment,
// but we can't always expect to receive them before the applier
// exits, because the WaitTask is skipped when the ApplyTask errors.
// So don't bother sending or expecting them.
statusEvents: []pollevent.Event{},
expectedStatusEvents: []testutil.ExpEvent{},
expectedEvents: []testutil.ExpEvent{
{
EventType: event.InitType,
Expand Down Expand Up @@ -1505,7 +1479,7 @@ func TestApplier(t *testing.T) {
var removed int
receivedEvents, removed = testutil.RemoveEqualEvents(receivedEvents, e)
if removed < 1 {
t.Fatalf("Expected status event not received: %#v", e.StatusEvent)
t.Errorf("Expected status event not received: %#v", e.StatusEvent)
}
}

Expand Down Expand Up @@ -1942,7 +1916,7 @@ func TestApplierCancel(t *testing.T) {
var removed int
receivedEvents, removed = testutil.RemoveEqualEvents(receivedEvents, e)
if removed < 1 {
t.Fatalf("Expected status event not received: %#v", e.StatusEvent)
t.Errorf("Expected status event not received: %#v", e.StatusEvent)
}
}

Expand Down

0 comments on commit 2ae0f05

Please sign in to comment.