From cf9fc37b1d389d45ac66489357a59124ddac8719 Mon Sep 17 00:00:00 2001 From: "(skovati) Luke" Date: Mon, 13 Nov 2023 14:06:34 -0800 Subject: [PATCH] add automatic validation test for runtime exception handling --- .../aerie/e2e/AutomaticValidationTests.java | 30 +++++++++++++++++++ .../aerie/e2e/types/ActivityValidation.java | 2 ++ 2 files changed, 32 insertions(+) diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java index 16b9460127..544967f84a 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java @@ -77,4 +77,34 @@ void validationSuccess() throws IOException, InterruptedException { final ActivityValidation activityValidation = activityValidations.get((long) activityId); assertEquals(new ActivityValidation.Success(), activityValidation); } + + @Test + void exceptionDuringValidationHandled() throws IOException, InterruptedException { + final var exceptionActivityId = hasura.insertActivity( + planId, + "ExceptionActivity", + "1h", + Json.createObjectBuilder().add("throwException", true).build()); + + // sleep to make sure exception activity is picked up + Thread.sleep(1000); // TODO consider a while loop here + + final var biteActivityId = hasura.insertActivity( + planId, + "BiteBanana", + "1h", + Json.createObjectBuilder().add("biteSize", 1).build()); + + Thread.sleep(1000); // TODO consider a while loop here + + final var activityValidations = hasura.getActivityValidations(planId); + + final ActivityValidation exceptionValidations = activityValidations.get((long) exceptionActivityId); + final ActivityValidation biteValidations = activityValidations.get((long) biteActivityId); + + // then make sure the exception was caught and serialized, and didn't crash the worker thread + assertEquals(new ActivityValidation.RuntimeError("Throwing runtime exception during validation"), exceptionValidations); + // if the above is true, bite banana will have its validation still + assertEquals(new ActivityValidation.Success(), biteValidations); + } } diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java index 599e84d394..2bf330e357 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java @@ -11,6 +11,7 @@ record Success() implements ActivityValidation {} record InstantiationFailure(List extraneousArguments, List missingArguments, List unconstructableArguments) implements ActivityValidation {} record ValidationFailure(List notices) implements ActivityValidation {} record NoSuchActivityTypeFailure(String message, String activityType) implements ActivityValidation {} + record RuntimeError(String message) implements ActivityValidation {} record ValidationNotice(List subjects, String message) { } record UnconstructableArgument(String name, String failure) { } @@ -44,6 +45,7 @@ static ActivityValidation fromJSON(JsonObject obj) { getStringArray($, "subjects"), $.asJsonObject().getString("message")))); case "NO_SUCH_ACTIVITY_TYPE" -> new NoSuchActivityTypeFailure(errors.getJsonObject("noSuchActivityError").getString("message"), errors.getJsonObject("noSuchActivityError").getString("activity_type")); + case "RUNTIME_EXCEPTION" -> new RuntimeError(errors.getString("runtimeException")); default -> throw new RuntimeException("Unhandled error type: " + type); }; }