From 44f489a5a370a0f46245402f3a0774bcd7688956 Mon Sep 17 00:00:00 2001 From: idawda Date: Mon, 25 Sep 2023 14:43:01 +0530 Subject: [PATCH] Fix the issue of failing few UTs due to delay in response --- .../instrumentation/jetty12/test/ServerTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/instrumentation-security/jetty-12/src/test/java/com/newrelic/agent/security/instrumentation/jetty12/test/ServerTest.java b/instrumentation-security/jetty-12/src/test/java/com/newrelic/agent/security/instrumentation/jetty12/test/ServerTest.java index cd8a9141c..ac11f2a3b 100644 --- a/instrumentation-security/jetty-12/src/test/java/com/newrelic/agent/security/instrumentation/jetty12/test/ServerTest.java +++ b/instrumentation-security/jetty-12/src/test/java/com/newrelic/agent/security/instrumentation/jetty12/test/ServerTest.java @@ -1,6 +1,5 @@ package com.newrelic.agent.security.instrumentation.jetty12.test; -import com.fasterxml.jackson.databind.ObjectMapper; import com.newrelic.agent.security.introspec.InstrumentationTestConfig; import com.newrelic.agent.security.introspec.SecurityInstrumentationTestRunner; import com.newrelic.agent.security.introspec.SecurityIntrospector; @@ -65,7 +64,7 @@ public void testHandle() throws Exception { List operations = introspector.getOperations(); Assert.assertTrue("No operations detected", operations.size() > 0); - System.out.println(new ObjectMapper().writeValueAsString(operations)); + RXSSOperation operation = (RXSSOperation) operations.get(0); Assert.assertEquals("Invalid event category.", VulnerabilityCaseType.REFLECTED_XSS, operation.getCaseType()); @@ -310,6 +309,7 @@ private void serviceWithoutHeaders() throws Exception { conn.connect(); System.out.println(conn.getResponseCode()); + waitForProcessing(); } @Trace(dispatcher = true) @@ -325,6 +325,7 @@ private String serviceWithHeaders() throws Exception { conn.connect(); conn.getResponseCode(); + waitForProcessing(); return headerValue; } @@ -335,4 +336,12 @@ private static int getRandomPort() { throw new RuntimeException("Unable to allocate ephemeral port "); } } + + private static void waitForProcessing() { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } }