From f0ebe5786ce37ddf6ebdcc5ec6de9bd7a81009b0 Mon Sep 17 00:00:00 2001 From: alex-butcher <21243172+abutch3r@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:37:50 +0000 Subject: [PATCH] Reorder waits and assertions to provide better result assurance 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. --- .../overflow/BeanWithFailOverflowStrategy.java | 7 ++----- .../overflow/FailOverflowStrategyOverflowTest.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/BeanWithFailOverflowStrategy.java b/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/BeanWithFailOverflowStrategy.java index 46d9062a..592e60f0 100644 --- a/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/BeanWithFailOverflowStrategy.java +++ b/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/BeanWithFailOverflowStrategy.java @@ -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; } diff --git a/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/FailOverflowStrategyOverflowTest.java b/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/FailOverflowStrategyOverflowTest.java index be5ded32..c848f369 100644 --- a/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/FailOverflowStrategyOverflowTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/reactive/messaging/tck/channel/overflow/FailOverflowStrategyOverflowTest.java @@ -43,9 +43,15 @@ public static Archive 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); + } }