mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
Stabilize SAM stack completion test (#1257)
* test(cloudformation): wait for SAM stack completion * test(cloudformation): tune SAM stack polling
This commit is contained in:
1 parent
79bf0d39a6
commit
2aebe174d5
1 file changed
+32
-35
+32
-35
@@ -69,15 +69,7 @@ class SamTransformIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
waitForStackStatus(stackName, "CREATE_COMPLETE");
|
||||
|
||||
given()
|
||||
.when()
|
||||
@@ -134,15 +126,7 @@ class SamTransformIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
waitForStackStatus(stackName, "CREATE_COMPLETE");
|
||||
|
||||
given()
|
||||
.when()
|
||||
@@ -562,23 +546,7 @@ class SamTransformIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String describeBody = null;
|
||||
for (int attempt = 0; attempt < 50; attempt++) {
|
||||
describeBody = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().asString();
|
||||
if (describeBody.contains("<StackStatus>CREATE_COMPLETE</StackStatus>")) {
|
||||
break;
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertThat(describeBody, containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
waitForStackStatus(stackName, "CREATE_COMPLETE");
|
||||
|
||||
given()
|
||||
.when()
|
||||
@@ -601,4 +569,33 @@ class SamTransformIntegrationTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForStackStatus(String stackName, String status) {
|
||||
String expected = "<StackStatus>" + status + "</StackStatus>";
|
||||
String body = "";
|
||||
long deadline = System.nanoTime() + java.time.Duration.ofSeconds(5).toNanos();
|
||||
while (System.nanoTime() < deadline) {
|
||||
body = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.asString();
|
||||
if (body.contains(expected)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new AssertionError("Interrupted while waiting for stack " + stackName
|
||||
+ " to reach " + expected, e);
|
||||
}
|
||||
}
|
||||
assertThat(body, containsString(expected));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user