Skip to content

Commit

Permalink
[sinttest] Carry over assertion message when sync point times out
Browse files Browse the repository at this point in the history
`AbstractSmackIntTest#assertResult()` takes an argument that is an assertion message. When the sync point times out, that message should be logged.

The following illustrates a stack trace of a failed test prior to this change:

```
SEVERE: MultiUserChatIntegrationTest.mucTest (Normal) failed: java.util.concurrent.TimeoutException: Timeout expired
java.util.concurrent.TimeoutException: Timeout expired
	at org.igniterealtime.smack.inttest.util.ResultSyncPoint.waitForResult(ResultSyncPoint.java:49)
	at org.igniterealtime.smack.inttest.AbstractSmackIntTest.assertResult(AbstractSmackIntTest.java:104)
	at org.igniterealtime.smack.inttest.AbstractSmackIntTest.assertResult(AbstractSmackIntTest.java:99)
	at org.jivesoftware.smackx.muc.MultiUserChatIntegrationTest.mucTest(MultiUserChatIntegrationTest.java:132)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	(snip)
```

With the change in this commit, that becomes:

```
SEVERE: MultiUserChatIntegrationTest.mucTest (Normal) failed: java.util.concurrent.TimeoutException: Expected smack-inttest-two-jskr4@example.org/two-jskr4 to receive message that was sent by smack-inttest-one-jskr4@example.org/one-jskr4 in room smack-inttest-message-jskr4-aud43i@conference.example.org (but it did not).
java.util.concurrent.TimeoutException: Expected smack-inttest-two-jskr4@example.org/two-jskr4 to receive message that was sent by smack-inttest-one-jskr4@example.org/one-jskr4 in room smack-inttest-message-jskr4-aud43i@conference.example.org (but it did not).
	at org.igniterealtime.smack.inttest.util.ResultSyncPoint.waitForResult(ResultSyncPoint.java:53)
	at org.igniterealtime.smack.inttest.AbstractSmackIntTest.assertResult(AbstractSmackIntTest.java:104)
	at org.igniterealtime.smack.inttest.AbstractSmackIntTest.assertResult(AbstractSmackIntTest.java:99)
	at org.jivesoftware.smackx.muc.MultiUserChatIntegrationTest.mucTest(MultiUserChatIntegrationTest.java:132)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	(snip)
```
  • Loading branch information
guusdk committed Apr 17, 2024
1 parent 2e94599 commit b12d73c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Expand Up @@ -101,7 +101,7 @@ public <R> R assertResult(ResultSyncPoint<R, ?> syncPoint, String message) throw

public static <R> R assertResult(ResultSyncPoint<R, ?> syncPoint, long timeout, String message) throws InterruptedException, TimeoutException, AssertionFailedError {
try {
return syncPoint.waitForResult(timeout);
return syncPoint.waitForResult(timeout, message);
} catch (InterruptedException | TimeoutException e) {
throw e;
} catch (Exception e) {
Expand Down
Expand Up @@ -26,6 +26,10 @@ public class ResultSyncPoint<R, E extends Exception> {
private E exception;

public R waitForResult(long timeout) throws E, InterruptedException, TimeoutException {
return waitForResult(timeout, null);
}

public R waitForResult(long timeout, String timeoutMessage) throws E, InterruptedException, TimeoutException {
synchronized (this) {
if (result != null) {
return result;
Expand All @@ -46,7 +50,7 @@ public R waitForResult(long timeout) throws E, InterruptedException, TimeoutExce
if (exception != null) {
throw exception;
}
throw new TimeoutException("Timeout expired");
throw new TimeoutException(timeoutMessage == null ? "Timeout expired" : timeoutMessage);
}


Expand Down

0 comments on commit b12d73c

Please sign in to comment.