Skip to content

Commit ad5982e

Browse files
committed
updated tests
1 parent 37f27ab commit ad5982e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

endtoendtests/src/main/java/com/functions/RewindTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ public HttpResponseMessage startRewindableOrchestration(
7171

7272
/**
7373
* HTTP trigger that starts a non-failing orchestration, waits for it to complete,
74-
* then attempts to rewind it using client.rewindInstance(). Returns the check status
75-
* response so the caller can verify the orchestration remains in the Completed state.
74+
* then attempts to rewind it using client.rewindInstance(). The sidecar should reject
75+
* the rewind with FAILED_PRECONDITION (translated to IllegalStateException) since
76+
* the instance is not in a Failed state. Returns 200 with the exception message on
77+
* expected rejection, or 500 if the rewind unexpectedly succeeded.
7678
*/
7779
@FunctionName("StartRewindNonFailedOrchestration")
7880
public HttpResponseMessage startRewindNonFailedOrchestration(
@@ -104,12 +106,16 @@ public HttpResponseMessage startRewindNonFailedOrchestration(
104106
// in a Failed state. The client translates this to an IllegalStateException.
105107
try {
106108
client.rewindInstance(instanceId, "Testing rewind on non-failed orchestration");
107-
context.getLogger().info("Rewind request sent for non-failed instance: " + instanceId);
109+
// If we get here, the rewind did not throw as expected
110+
return request.createResponseBuilder(com.microsoft.azure.functions.HttpStatus.INTERNAL_SERVER_ERROR)
111+
.body("IllegalStateException was not thrown for non-failed instance")
112+
.build();
108113
} catch (IllegalStateException e) {
109114
context.getLogger().info("Rewind on non-failed instance was rejected (expected): " + e.getMessage());
115+
return request.createResponseBuilder(com.microsoft.azure.functions.HttpStatus.OK)
116+
.body(e.getMessage())
117+
.build();
110118
}
111-
112-
return durableContext.createCheckStatusResponse(request, instanceId);
113119
}
114120

115121
/**

endtoendtests/src/test/java/com/functions/EndToEndTests.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,16 @@ public void rewindNonExistentOrchestration() throws InterruptedException {
270270
@Test
271271
public void rewindNonFailedOrchestration() throws InterruptedException {
272272
// Start a non-failing orchestration - the trigger waits for completion
273-
// and then calls client.rewindInstance() internally before returning
273+
// and then calls client.rewindInstance() internally before returning.
274+
// The rewind should be rejected with IllegalStateException since the
275+
// instance is not in a Failed state.
274276
String startOrchestrationPath = "/api/StartRewindNonFailedOrchestration";
275277
Response response = post(startOrchestrationPath);
276-
JsonPath jsonPath = response.jsonPath();
277-
String statusQueryGetUri = jsonPath.get("statusQueryGetUri");
278-
279-
// Wait a few seconds to allow any potential state change from the rewind attempt
280-
Thread.sleep(5000);
281-
282-
// Verify the orchestration remains in Completed state (rewind should have no effect)
283-
Response statusResponse = get(statusQueryGetUri);
284-
String status = statusResponse.jsonPath().get("runtimeStatus");
285-
assertEquals("Completed", status,
286-
"Orchestration should remain Completed after rewind attempt on a non-failed instance");
278+
assertEquals(200, response.getStatusCode(),
279+
"Expected 200 OK indicating the IllegalStateException was caught. Body: " + response.getBody().asString());
280+
String body = response.getBody().asString();
281+
assertTrue(body.contains("is not in a failed state") && body.contains("cannot be rewound"),
282+
"Response should contain the precondition error message, but was: " + body);
287283
}
288284

289285
@Test

0 commit comments

Comments
 (0)