diff options
author | Ittay Stern <ittay.stern@att.com> | 2020-03-23 07:24:50 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2020-03-23 05:27:20 +0000 |
commit | 9c411472a8aa8a218665d258f52c3d436ee9b58e (patch) | |
tree | 410ebaffb7e050d212060f88598f71f1c12170a6 /vid-automation/src/test | |
parent | efefd95854efb51333dc36abe7bb33fca4d04e90 (diff) |
Add some timed grace for assertion on log-lines
It happens that logging is delayed, and rows are not available on disk
right after an inspected event.
Issue-ID: VID-647
Change-Id: Ic47cb2beff0be699f018ff6b5f264a57479bd7d0
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-automation/src/test')
-rw-r--r-- | vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java | 5 | ||||
-rw-r--r-- | vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java | 40 |
2 files changed, 24 insertions, 21 deletions
diff --git a/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java b/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java index b27d6a8af..1cd6077ff 100644 --- a/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java +++ b/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalToIgnoringCase; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.collection.IsMapContaining.hasKey; +import static org.onap.vid.api.TestUtils.assertAndRetryIfNeeded; import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND; import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET; import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset; @@ -41,11 +42,11 @@ public class AuditLoggerTest extends BaseApiTest { registerExpectationFromPreset(new PresetAAIGetVpnsByType(), APPEND); String requestId = getRequestId(() -> restTemplate.getForEntity(buildUri("aai_get_vpn_list"), String.class)); - assertThat("request id must be found in exactly two rows", getRequestLogLines(requestId), + assertAndRetryIfNeeded(5, () -> assertThat("request id must be found in exactly two rows", getRequestLogLines(requestId), contains( allOf(containsString(requestId), containsString("Entering")), allOf(containsString(requestId), containsString("Exiting")) - )); + ))); } private List<String> getRequestLogLines(String requestId) { diff --git a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java index 962a7860f..f148689d1 100644 --- a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java +++ b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java @@ -15,6 +15,7 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.matchesPattern; +import static org.onap.vid.api.TestUtils.assertAndRetryIfNeeded; import static vid.automation.test.services.SimulatorApi.retrieveRecordedRequests; import com.fasterxml.jackson.databind.JsonNode; @@ -166,30 +167,29 @@ public class LoggerFormatTest extends BaseApiTest { } public static void verifyExistenceOfIncomingReqsInAuditLogs (RestTemplate restTemplate, URI uri, String requestId, String path){ - List<String> logLines = getRequestLogLines(requestId, LogName.audit2019, restTemplate, uri); - String requestIdPrefix = "RequestID="; - assertThat("\nENTRY & EXIT logs are expected to include RequestId: " + requestId - + " \nAnd request path: " - + path + - "\nin exactly two rows - inside the audit log matching lines:\n" - + String.join("\n", logLines) + "\n", + assertAndRetryIfNeeded(5, () -> { + List<String> logLines = getRequestLogLines(requestId, LogName.audit2019, restTemplate, uri); + String requestIdPrefix = "RequestID="; + assertThat("\nENTRY & EXIT logs are expected to include RequestId: " + requestId + + " \nAnd request path: " + + path + + "\nin exactly two rows - inside the audit log matching lines:\n" + + String.join("\n", logLines) + "\n", logLines, contains( - allOf( - containsString(requestIdPrefix + requestId), - containsString("ENTRY"), - containsString(path)), - allOf( - containsString(requestIdPrefix + requestId), - containsString("EXIT"), - containsString(path)) + allOf( + containsString(requestIdPrefix + requestId), + containsString("ENTRY"), + containsString(path)), + allOf( + containsString(requestIdPrefix + requestId), + containsString("EXIT"), + containsString(path)) )); + }); } public static void assertHeadersAndMetricLogs (RestTemplate restTemplate, URI uri, String requestId, String path, int requestsSize){ - List<String> logLines = - getRequestLogLines(requestId, LogName.metrics2019, restTemplate, uri); - List<RecordedRequests> requests = retrieveRecordedRequests(); List<RecordedRequests> underTestRequests = requests.stream().filter(x -> x.path.contains(path)).collect(toList()); @@ -212,7 +212,9 @@ public class LoggerFormatTest extends BaseApiTest { String invocationId = invocationIds.get(0); allInvocationIds.add(invocationId); - assertIdsInMetricsLog(logLines, requestId, invocationId); + assertAndRetryIfNeeded(5, () -> assertIdsInMetricsLog( + getRequestLogLines(requestId, LogName.metrics2019, restTemplate, uri), requestId, invocationId) + ); }); //make sure no InvocationId is repeated twice |