diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-09-15 11:26:55 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-09-15 11:26:55 +0200 |
commit | ae493251bb20f9405fb85eb30b0de6e6ee98842e (patch) | |
tree | 0a93bbc85c71b9b51528d873f9d2eb533388c20a /jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty | |
parent | cac180765acf594c711fb8675521af566689118e (diff) |
Wait for statistics
Diffstat (limited to 'jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty')
-rw-r--r-- | jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java index b6bd017a6d9..96cf1d4c01f 100644 --- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java +++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java @@ -585,37 +585,48 @@ public class HttpServerTest { { driver.client().newPost("/status.html").execute(); - List<HttpResponseStatisticsCollector.StatisticsEntry> stats = statisticsCollector.takeStatistics(); - assertEquals(1, stats.size()); - assertEquals("http", stats.get(0).scheme); - assertEquals("POST", stats.get(0).method); - assertEquals("http.status.2xx", stats.get(0).name); - assertEquals("write", stats.get(0).requestType); - assertEquals(1, stats.get(0).value); + var entry = waitForStatistics(statisticsCollector); + assertEquals("http", entry.scheme); + assertEquals("POST", entry.method); + assertEquals("http.status.2xx", entry.name); + assertEquals("write", entry.requestType); + assertEquals(1, entry.value); } { driver.client().newGet("/status.html").execute(); - List<HttpResponseStatisticsCollector.StatisticsEntry> stats = statisticsCollector.takeStatistics(); - assertEquals(1, stats.size()); - assertEquals("http", stats.get(0).scheme); - assertEquals("GET", stats.get(0).method); - assertEquals("http.status.2xx", stats.get(0).name); - assertEquals("read", stats.get(0).requestType); - assertEquals(1, stats.get(0).value); + var entry = waitForStatistics(statisticsCollector); + assertEquals("http", entry.scheme); + assertEquals("GET", entry.method); + assertEquals("http.status.2xx", entry.name); + assertEquals("read", entry.requestType); + assertEquals(1, entry.value); } { handler.setRequestType(Request.RequestType.READ); driver.client().newPost("/status.html").execute(); - List<HttpResponseStatisticsCollector.StatisticsEntry> stats = statisticsCollector.takeStatistics(); - assertEquals(1, stats.size()); - assertEquals("Handler overrides request type", "read", stats.get(0).requestType); + var entry = waitForStatistics(statisticsCollector); + assertEquals("Handler overrides request type", "read", entry.requestType); } assertTrue(driver.close()); } + private HttpResponseStatisticsCollector.StatisticsEntry waitForStatistics(HttpResponseStatisticsCollector + statisticsCollector) { + List<HttpResponseStatisticsCollector.StatisticsEntry> entries = Collections.emptyList(); + int tries = 0; + while (entries.isEmpty() && tries < 10000) { + entries = statisticsCollector.takeStatistics(); + if (entries.isEmpty()) + try {Thread.sleep(100); } catch (InterruptedException e) {} + tries++; + } + assertEquals(1, entries.size()); + return entries.get(0); + } + @Test public void requireThatConnectionThrottleDoesNotBlockConnectionsBelowThreshold() throws Exception { TestDriver driver = TestDrivers.newConfiguredInstance( |