Skip to content

Commit

Permalink
Making HttpInMetricTest more reliable against failure (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusoe authored Aug 4, 2020
1 parent 3488577 commit 296d6a4
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
*/
public class HttpInMetricTest {

public static final int PORT = 9999;

private Server server;


void fireRequest(String url) {
try {
HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
Expand All @@ -48,16 +45,14 @@ public static class TestServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(123);
}

}

@Nested
class ServletAPI {

@Test
void testRequestRecorded() throws Exception {

server = new Server(PORT);
server = new Server(0);
ServletHandler servletHandler = new ServletHandler();
server.setHandler(servletHandler);
servletHandler.addServletWithMapping(TestServlet.class, "/*");
Expand All @@ -66,9 +61,10 @@ void testRequestRecorded() throws Exception {
TestUtils.waitForClassInstrumentations(Arrays.asList(HttpServlet.class,
Class.forName("sun.net.www.protocol.http.HttpURLConnection")), 10, TimeUnit.SECONDS);

fireRequest("http://localhost:" + PORT + "/servletapi");
fireRequest("http://localhost:" + server.getURI().getPort() + "/servletapi");
server.stop();

TestUtils.waitForOpenCensusQueueToBeProcessed();

Map<String, String> tags = new HashMap<>();
tags.put("http_path", "/servletapi");
Expand Down

0 comments on commit 296d6a4

Please sign in to comment.