Skip to content

Commit

Permalink
introspect failed scheduling run reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
skovati authored and JoelCourtney committed Sep 9, 2024
1 parent 0dcdbc3 commit a2e0898
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,9 @@ void proceduralUploadWorks() throws IOException {
*/
@Test
void executeSchedulingRunWithoutArguments() throws IOException {
assertThrows(AssertionFailedError.class, () -> hasura.awaitScheduling(specId));
final var resp = hasura.awaitFailingScheduling(specId);
final var message = resp.reason().getString("message");
assertTrue(message.contains("java.lang.RuntimeException: Record missing key Component[name=quantity"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,38 @@ public SchedulingResponse awaitScheduling(int schedulingSpecId, int timeout) thr
throw new TimeoutError("Scheduling timed out after " + timeout + " seconds");
}

/**
* Run scheduling on the specified scheduling specification with a timeout of 30 seconds
* Used when the scheduling run is expected to fail.
*/
public SchedulingResponse awaitFailingScheduling(int schedulingSpecId) throws IOException {
return awaitFailingScheduling(schedulingSpecId, 30);
}

/**
* Run scheduling on the specified scheduling specification
* Used when the scheduling run is expected to fail.
*/
public SchedulingResponse awaitFailingScheduling(int schedulingSpecId, int timeout) throws IOException {
for(int i = 0; i < timeout; ++i){
final var response = schedule(schedulingSpecId);
switch (response.status()) {
case "pending", "incomplete" -> {
try {
Thread.sleep(1000); // 1s
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
case "complete", "failed" -> {
return response;
}
default -> fail("Scheduling returned bad status " + response.status() + " with reason " +response.reason());
}
}
throw new TimeoutError("Scheduling timed out after " + timeout + " seconds");
}

/**
* Start and immediately cancel a scheduling run with a timeout of 30 seconds
* @param schedulingSpecId the scheduling specification to use
Expand Down

0 comments on commit a2e0898

Please sign in to comment.