Skip to content

Commit 76b1ab5

Browse files
committed
Remove duplicated infrastructure clearnup in LoggingE2E.
1 parent 88a26a0 commit 76b1ab5

File tree

1 file changed

+26
-35
lines changed
  • powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools

1 file changed

+26
-35
lines changed

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/LoggingE2ET.java

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.util.stream.Collectors;
2626
import java.util.stream.Stream;
2727

28-
import org.junit.jupiter.api.AfterAll;
28+
import org.junit.jupiter.api.AfterEach;
2929
import org.junit.jupiter.api.TestInstance;
3030
import org.junit.jupiter.api.Timeout;
3131
import org.junit.jupiter.params.ParameterizedTest;
@@ -62,7 +62,7 @@ private void setupInfrastructure(String pathToFunction) {
6262
functionName = outputs.get(FUNCTION_NAME_OUTPUT);
6363
}
6464

65-
@AfterAll
65+
@AfterEach
6666
void tearDown() {
6767
if (infrastructure != null) {
6868
infrastructure.destroy();
@@ -75,38 +75,29 @@ void tearDown() {
7575
void test_logInfoWithAdditionalKeys(String pathToFunction) throws JsonProcessingException {
7676
setupInfrastructure(pathToFunction);
7777

78-
try {
79-
// GIVEN
80-
String orderId = UUID.randomUUID().toString();
81-
String event = "{\"message\":\"New Order\", \"keys\":{\"orderId\":\"" + orderId + "\"}}";
82-
83-
// WHEN
84-
InvocationResult invocationResult1 = invokeFunction(functionName, event);
85-
InvocationResult invocationResult2 = invokeFunction(functionName, event);
86-
87-
// THEN
88-
String[] functionLogs = invocationResult1.getLogs().getFunctionLogs(INFO);
89-
assertThat(functionLogs).hasSize(1);
90-
91-
JsonNode jsonNode = objectMapper.readTree(functionLogs[0]);
92-
assertThat(jsonNode.get("message").asText()).isEqualTo("New Order");
93-
assertThat(jsonNode.get("orderId").asText()).isEqualTo(orderId);
94-
assertThat(jsonNode.get("cold_start").asBoolean()).isTrue();
95-
assertThat(jsonNode.get("xray_trace_id").asText()).isNotBlank();
96-
assertThat(jsonNode.get("function_request_id").asText()).isEqualTo(invocationResult1.getRequestId());
97-
98-
// second call should not be cold start
99-
functionLogs = invocationResult2.getLogs().getFunctionLogs(INFO);
100-
assertThat(functionLogs).hasSize(1);
101-
jsonNode = objectMapper.readTree(functionLogs[0]);
102-
assertThat(jsonNode.get("cold_start").asBoolean()).isFalse();
103-
104-
} finally {
105-
// Clean up infrastructure after each parameter
106-
if (infrastructure != null) {
107-
infrastructure.destroy();
108-
infrastructure = null;
109-
}
110-
}
78+
// GIVEN
79+
String orderId = UUID.randomUUID().toString();
80+
String event = "{\"message\":\"New Order\", \"keys\":{\"orderId\":\"" + orderId + "\"}}";
81+
82+
// WHEN
83+
InvocationResult invocationResult1 = invokeFunction(functionName, event);
84+
InvocationResult invocationResult2 = invokeFunction(functionName, event);
85+
86+
// THEN
87+
String[] functionLogs = invocationResult1.getLogs().getFunctionLogs(INFO);
88+
assertThat(functionLogs).hasSize(1);
89+
90+
JsonNode jsonNode = objectMapper.readTree(functionLogs[0]);
91+
assertThat(jsonNode.get("message").asText()).isEqualTo("New Order");
92+
assertThat(jsonNode.get("orderId").asText()).isEqualTo(orderId);
93+
assertThat(jsonNode.get("cold_start").asBoolean()).isTrue();
94+
assertThat(jsonNode.get("xray_trace_id").asText()).isNotBlank();
95+
assertThat(jsonNode.get("function_request_id").asText()).isEqualTo(invocationResult1.getRequestId());
96+
97+
// second call should not be cold start
98+
functionLogs = invocationResult2.getLogs().getFunctionLogs(INFO);
99+
assertThat(functionLogs).hasSize(1);
100+
jsonNode = objectMapper.readTree(functionLogs[0]);
101+
assertThat(jsonNode.get("cold_start").asBoolean()).isFalse();
111102
}
112103
}

0 commit comments

Comments
 (0)