Skip to content

Commit d1cb3a7

Browse files
authored
Merge pull request #1024 from microsoft/fix_flaky_test
Test is being flaky
2 parents 7819229 + 141ed02 commit d1cb3a7

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

web/src/test/java/com/microsoft/applicationinsights/web/internal/httputils/HttpServerHandlerTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import org.junit.Rule;
1414
import org.junit.Test;
1515
import org.junit.rules.ExpectedException;
16-
import org.junit.runner.RunWith;
17-
import org.junit.runners.JUnit4;
1816
import org.mockito.InOrder;
1917
import org.mockito.InjectMocks;
2018
import org.mockito.Mock;
@@ -25,14 +23,12 @@
2523
import javax.servlet.http.HttpServletResponse;
2624
import java.net.MalformedURLException;
2725
import java.util.Date;
26+
import java.util.concurrent.TimeUnit;
2827

29-
import static org.hamcrest.CoreMatchers.*;
30-
import static org.hamcrest.MatcherAssert.assertThat;
31-
import static org.hamcrest.core.Is.is;
32-
import static org.hamcrest.core.StringContains.containsString;
28+
import static org.hamcrest.Matchers.*;
29+
import static org.junit.Assert.*;
3330
import static org.mockito.Mockito.*;
3431

35-
@RunWith(JUnit4.class)
3632
public class HttpServerHandlerTest {
3733

3834
@Rule public final ExpectedException thrown = ExpectedException.none();
@@ -152,7 +148,7 @@ public void requestTelemetryFieldsAreSetWhenHandleStartIsInvoked() throws Malfor
152148
}
153149

154150
@Test
155-
public void timeStatusCodeAreSetWhenHandleEndIsInvoked() throws MalformedURLException {
151+
public void timeStatusCodeAreSetWhenHandleEndIsInvoked() throws Exception {
156152
RequestTelemetryContext rtc = httpServerHandler.handleStart(request, response);
157153
RequestTelemetry rt = rtc.getHttpRequestTelemetry();
158154
assertThat(rt.getId(), is(CoreMatchers.<String>notNullValue()));
@@ -161,7 +157,7 @@ public void timeStatusCodeAreSetWhenHandleEndIsInvoked() throws MalformedURLExce
161157
assertThat(rt.getUrl().toString(), equalTo(url));
162158
assertThat(rt.getContext().getUser().getUserAgent(), equalTo("User-Agent"));
163159
assertThat(rt.getTimestamp(), is(CoreMatchers.<Date>notNullValue()));
164-
160+
TimeUnit.MILLISECONDS.sleep(100); // pause so duration is nonzero
165161
httpServerHandler.handleEnd(request, response, rtc);
166162
// ensure same request telemetry is modified (picked from TLS)
167163
assertThat(rt.getDuration().getTotalMilliseconds(), is(not(0L)));

0 commit comments

Comments
 (0)