Skip to content

Commit

Permalink
test: fix CreateAndDeleteResource undeterministic order of events
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Apr 22, 2022
1 parent ee50cad commit a64620a
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions grpc-gateway/service/createAndDeleteResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func createSwitchResourceExpectedEvents(t *testing.T, deviceID, subID, correlati
}
}

func deleteSwitchResourceExpectedEvents(t *testing.T, deviceID, subID, correlationID, switchID string) map[string]*pb.Event {
func deleteSwitchResourceExpectedEvents(t *testing.T, deviceID, subID, correlationID, switchID string, isDiscoveryResourceBatchObservable bool) map[string]*pb.Event {
deletePending := &pb.Event{
SubscriptionId: subID,
CorrelationId: correlationID,
Expand Down Expand Up @@ -199,27 +199,25 @@ func deleteSwitchResourceExpectedEvents(t *testing.T, deviceID, subID, correlati
},
}

return map[string]*pb.Event{
e := map[string]*pb.Event{
pbTest.GetEventID(deletePending): deletePending,
pbTest.GetEventID(deleted): deleted,
pbTest.GetEventID(unpublished): unpublished,
pbTest.GetEventID(changed): changed,
}
}

func batchDeleteSwitchChangedResourceExpected(t *testing.T, deviceID, subID, correlationID, switchID string) map[string]*pb.Event {

changed := &pb.Event{
SubscriptionId: subID,
CorrelationId: correlationID,
Type: &pb.Event_ResourceChanged{
ResourceChanged: pbTest.MakeResourceChanged(t, deviceID, test.TestResourceSwitchesInstanceHref(switchID), "", map[interface{}]interface{}{}),
},
if isDiscoveryResourceBatchObservable {
changedRes := &pb.Event{
SubscriptionId: subID,
CorrelationId: correlationID,
Type: &pb.Event_ResourceChanged{
ResourceChanged: pbTest.MakeResourceChanged(t, deviceID, test.TestResourceSwitchesInstanceHref(switchID), "", map[interface{}]interface{}{}),
},
}
e[pbTest.GetEventID(changedRes)] = changedRes
}

return map[string]*pb.Event{
pbTest.GetEventID(changed): changed,
}
return e
}

func validateEvents(t *testing.T, subClient pb.GrpcGateway_SubscribeToEventsClient, expectedEvents map[string]*pb.Event) {
Expand Down Expand Up @@ -277,12 +275,7 @@ func TestCreateAndDeleteResource(t *testing.T) {
expectedCreateEvents := createSwitchResourceExpectedEvents(t, deviceID, subID, correlationID, switchID)
validateEvents(t, subClient, expectedCreateEvents)
deleteSwitchResource(t, ctx, c, deviceID, switchID)
expectedDeleteEvents := deleteSwitchResourceExpectedEvents(t, deviceID, subID, correlationID, switchID)
expectedDeleteEvents := deleteSwitchResourceExpectedEvents(t, deviceID, subID, correlationID, switchID, isDiscoveryResourceBatchObservable)
validateEvents(t, subClient, expectedDeleteEvents)

if isDiscoveryResourceBatchObservable {
expectedEvents := batchDeleteSwitchChangedResourceExpected(t, deviceID, subID, correlationID, switchID)
validateEvents(t, subClient, expectedEvents)
}
}
}

0 comments on commit a64620a

Please sign in to comment.