Ensure retryable writes tests fail when unexpected exception is thrown
Also, ensure that the stack trace of the unexpected exception is
included in build output by re-throwing the exception.
@@ -138,21 +138,17 @@ public abstract class AbstractRetryableWritesTest {
BsonDocument operation = definition.getDocument("operation");
BsonDocument outcome = definition.getDocument("outcome");
+ boolean isErrorExpected = outcome.getBoolean("error", BsonBoolean.FALSE).getValue();
- BsonDocument result = new BsonDocument();
- boolean wasException = false;
try {
- result = helper.getOperationResults(operation);
+ BsonDocument result = helper.getOperationResults(operation);
+ assertFalse("Expected error but instead got result: " + result.toJson(), isErrorExpected);
+ assertEquals(outcome.getDocument("result", new BsonDocument()), result.getDocument("result", new BsonDocument()));
} catch (RuntimeException e) {
- wasException = true;
- assertExceptionState(e, outcome.get("result", new BsonNull()), operation.getString("name").getValue());
+ if (!isErrorExpected) {
+ throw e;
}
-
- if (outcome.getBoolean("error", BsonBoolean.FALSE).getValue()) {
- assertEquals("Expected an error to be thrown", outcome.containsKey("error"), wasException);
- } else {
- BsonDocument fixedExpectedResult = outcome.getDocument("result", new BsonDocument());
- assertEquals(fixedExpectedResult, result.getDocument("result", new BsonDocument()));
+ assertExceptionState(e, outcome.get("result", new BsonNull()), operation.getString("name").getValue());
}
if (outcome.containsKey("collection")) {
