Skip to content

Commit

Permalink
Reorder waits and assertions to provide better result assurance
Browse files Browse the repository at this point in the history
Wait for the failure on the stream to occur instead of the exception on the emitter - this ensures that at least the first message will be sucessfully processed and that a failure did occur before assertions are checked.

In the case where the failure may occur sufficiently late in the test execution such that there is a failure, but not yet an exception. In this case emit one more message and wait for the exception before checking

emitThree was unused and would close close the stream via `.complete()` - repurpose for being able to send one message and not close the stream if successful.
  • Loading branch information
abutch3r committed Feb 29, 2024
1 parent 29dfac9 commit f0ebe57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Expand Up @@ -68,12 +68,9 @@ public Exception exception() {
return callerException;
}

public void emitThree() {
public void emitOne() {
try {
emitter.send("1");
emitter.send("2");
emitter.send("3");
emitter.complete();
emitter.send("1000");
} catch (Exception e) {
callerException = e;
}
Expand Down
Expand Up @@ -43,9 +43,15 @@ public static Archive<JavaArchive> deployment() {
public void testOverflow() {
bean.emitALotOfItems();

await().until(() -> bean.exception() != null);
assertThat(bean.output()).doesNotContain("999");
await().until(() -> bean.failure() != null);
assertThat(bean.failure()).isInstanceOf(Exception.class);
assertThat(bean.output()).isNotEmpty().hasSizeLessThan(999);
assertThat(bean.failure()).isNotNull().isInstanceOf(Exception.class);
//If an exception has not yet been thrown after the failure occurred, try one more message
if (bean.exception() == null) {
bean.emitOne();
await().until(() -> bean.exception() != null);
}
assertThat(bean.exception()).isInstanceOf(IllegalStateException.class);

}
}

0 comments on commit f0ebe57

Please sign in to comment.