1
0
mirror of synced 2026-08-05 15:06:54 +00:00

fix: unflake TestPageRequestFallback.shouldChainOnce on win (#1058)

This commit is contained in:
Yury Semikhatsky
2022-09-12 16:44:14 -07:00
committed by GitHub
parent 020618d83d
commit 5979077403
2 changed files with 24 additions and 21 deletions
@@ -38,19 +38,16 @@ class Router {
this.times = times;
}
boolean handle(RouteImpl route) {
if (!matcher.test(route.request().url())) {
return false;
}
if (times != null) {
--times;
}
void handle(RouteImpl route) {
handler.accept(route);
return true;
}
boolean isDone() {
return times != null && times <= 0;
boolean decrementRemainingCallCount() {
if (times == null) {
return false;
}
--times;
return times <= 0;
}
}
@@ -73,14 +70,16 @@ class Router {
HandleResult result = HandleResult.NoMatchingHandler;
for (Iterator<RouteInfo> it = routes.iterator(); it.hasNext();) {
RouteInfo info = it.next();
if (info.handle(route)) {
result = HandleResult.FoundMatchingHandler;
if (info.isDone()) {
it.remove();
}
if (route.isHandled()) {
break;
}
if (!info.matcher.test(route.request().url())) {
continue;
}
if (info.decrementRemainingCallCount()) {
it.remove();
}
result = HandleResult.FoundMatchingHandler;
info.handle(route);
if (route.isHandled()) {
break;
}
}
return result;
@@ -19,6 +19,7 @@ package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -127,13 +128,16 @@ public class TestPageRequestFallback extends TestBase {
@Test
void shouldChainOnce() {
page.route("**/empty.html", route -> {
boolean didFulfill[] = {false};
page.route("**/title.html", route -> {
route.fulfill(new Route.FulfillOptions().setStatus(200).setBody("fulfilled one"));
didFulfill[0] = true;
}, new Page.RouteOptions().setTimes(1));
page.route("**/empty.html", route -> {
page.route("**/title.html", route -> {
route.fallback();
}, new Page.RouteOptions().setTimes(1));
Response response = page.navigate(server.EMPTY_PAGE);
Response response = page.navigate(server.PREFIX + "/title.html");
assertTrue(didFulfill[0]);
assertEquals("fulfilled one", response.text());
}