Skip to content

Commit 6292e66

Browse files
committed
add a bit more detail to timeout message when waiting for health check request telemetry
1 parent f0f2d54 commit 6292e66

File tree

1 file changed

+30
-19
lines changed
  • test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest

1 file changed

+30
-19
lines changed

test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/AiSmokeTest.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.Map.Entry;
5454
import java.util.Properties;
5555
import java.util.Random;
56+
import java.util.concurrent.ExecutionException;
5657
import java.util.concurrent.TimeUnit;
5758
import java.util.concurrent.atomic.AtomicReference;
5859

@@ -363,27 +364,38 @@ protected static void waitForApplicationToStart() throws Exception {
363364
String.format("%s on %s", getAppContext(), containerInfo.getImageName()),
364365
HEALTH_CHECK_RETRIES);
365366
System.out.println("Test app health check complete.");
366-
if (requestCaptureEnabled) {
367-
Stopwatch sw = Stopwatch.createStarted();
368-
mockedIngestion.waitForItem(new Predicate<Envelope>() {
369-
@Override
370-
public boolean apply(Envelope input) {
371-
if (!"RequestData".equals(input.getData().getBaseType())) {
372-
return false;
373-
}
374-
RequestData data = (RequestData) ((Data) input.getData()).getBaseData();
375-
return contextRootUrl.equals(data.getUrl()) && "200".equals(data.getResponseCode());
376-
}
377-
}, TELEMETRY_RECEIVE_TIMEOUT_SECONDS, TimeUnit.SECONDS);
378-
System.out.printf("Received request telemetry after %.3f seconds...%n",
379-
sw.elapsed(TimeUnit.MILLISECONDS) / 1000.0);
380-
System.out.println("Clearing any RequestData from health check.");
381-
}
367+
waitForHealthCheckTelemetryIfNeeded(contextRootUrl);
382368
} catch (Exception e) {
383369
docker.printContainerLogs(containerInfo.getContainerId());
384370
throw e;
371+
} finally {
372+
mockedIngestion.resetData();
373+
}
374+
}
375+
376+
private static void waitForHealthCheckTelemetryIfNeeded(final String contextRootUrl) throws InterruptedException, ExecutionException {
377+
if (!requestCaptureEnabled) {
378+
return;
379+
}
380+
381+
Stopwatch receivedTelemetryTimer = Stopwatch.createStarted();
382+
final int requestTelemetryFromHealthCheckTimeout = TELEMETRY_RECEIVE_TIMEOUT_SECONDS;
383+
try {
384+
mockedIngestion.waitForItem(new Predicate<Envelope>() {
385+
@Override
386+
public boolean apply(Envelope input) {
387+
if (!"RequestData".equals(input.getData().getBaseType())) {
388+
return false;
389+
}
390+
RequestData data = (RequestData) ((Data) input.getData()).getBaseData();
391+
return contextRootUrl.equals(data.getUrl()) && "200".equals(data.getResponseCode());
392+
}
393+
}, requestTelemetryFromHealthCheckTimeout, TimeUnit.SECONDS);
394+
System.out.printf("Received request telemetry after %.3f seconds...%n", receivedTelemetryTimer.elapsed(TimeUnit.MILLISECONDS) / 1000.0);
395+
System.out.println("Clearing any RequestData from health check.");
396+
} catch (java.util.concurrent.TimeoutException e) {
397+
throw new TimeoutException("request telemetry from application health check", requestTelemetryFromHealthCheckTimeout, TimeUnit.SECONDS, e);
385398
}
386-
mockedIngestion.resetData();
387399
}
388400

389401
protected void callTargetUriAndWaitForTelemetry() throws Exception {
@@ -710,8 +722,7 @@ protected static void waitForUrl(String url, long timeout, TimeUnit timeoutUnit,
710722
assertFalse(String.format("Empty response from '%s'. Health check urls should return something non-empty", url), rval.isEmpty());
711723
}
712724

713-
protected static void waitForUrlWithRetries(String url, long timeout, TimeUnit timeoutUnit, String appName, int numberOfRetries)
714-
throws IOException {
725+
protected static void waitForUrlWithRetries(String url, long timeout, TimeUnit timeoutUnit, String appName, int numberOfRetries) throws IOException {
715726
Preconditions.checkArgument(numberOfRetries >= 0, "numberOfRetries must be non-negative");
716727
int triedCount = 0;
717728
boolean success = false;

0 commit comments

Comments
 (0)