fix race in DeviceGroupTest, #22893

This commit is contained in:
Patrik Nordwall 2017-05-15 15:49:37 +02:00
parent ccb587209f
commit 2cc65e73a1
6 changed files with 50 additions and 26 deletions

View file

@ -122,10 +122,16 @@ public class DeviceGroupTest extends JUnitSuite {
toShutDown.tell(PoisonPill.getInstance(), ActorRef.noSender());
probe.expectTerminated(toShutDown);
groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef());
reply = probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class);
assertEquals(1L, reply.requestId);
assertEquals(Stream.of("device2").collect(Collectors.toSet()), reply.ids);
// using awaitAssert to retry because it might take longer for the groupActor
// to see the Terminated, that order is undefined
probe.awaitAssert(() -> {
groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef());
DeviceGroup.ReplyDeviceList r =
probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class);
assertEquals(1L, r.requestId);
assertEquals(Stream.of("device2").collect(Collectors.toSet()), r.ids);
return null;
});
}
//#device-group-list-terminate-test
}

View file

@ -121,10 +121,16 @@ public class DeviceGroupTest extends JUnitSuite {
toShutDown.tell(PoisonPill.getInstance(), ActorRef.noSender());
probe.expectTerminated(toShutDown);
groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef());
reply = probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class);
assertEquals(1L, reply.requestId);
assertEquals(Stream.of("device2").collect(Collectors.toSet()), reply.ids);
// using awaitAssert to retry because it might take longer for the groupActor
// to see the Terminated, that order is undefined
probe.awaitAssert(() -> {
groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef());
DeviceGroup.ReplyDeviceList r =
probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class);
assertEquals(1L, r.requestId);
assertEquals(Stream.of("device2").collect(Collectors.toSet()), r.ids);
return null;
});
}
//#group-query-integration-test

View file

@ -120,10 +120,16 @@ public class DeviceGroupTest extends JUnitSuite {
toShutDown.tell(PoisonPill.getInstance(), ActorRef.noSender());
probe.expectTerminated(toShutDown);
groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef());
reply = probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class);
assertEquals(1L, reply.requestId);
assertEquals(Stream.of("device2").collect(Collectors.toSet()), reply.ids);
// using awaitAssert to retry because it might take longer for the groupActor
// to see the Terminated, that order is undefined
probe.awaitAssert(() -> {
groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef());
DeviceGroup.ReplyDeviceList r =
probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class);
assertEquals(1L, r.requestId);
assertEquals(Stream.of("device2").collect(Collectors.toSet()), r.ids);
return null;
});
}
@Test