Skip to content

Commit f569666

Browse files
committed
[grid] Improving flaky test in DistributorTest
Also, removing two tests that already exist in RouterTest.java
1 parent 03d8053 commit f569666

2 files changed

Lines changed: 39 additions & 82 deletions

File tree

.github/workflows/ci-java.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,36 @@ jobs:
8686
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8787
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
8888

89+
medium_tests:
90+
if: ${{ needs.check_workflow.outputs.result == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(toJson(github.event.commits), '[run java]') == true }}
91+
needs: [ check_workflow, small_tests ]
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: Checkout source tree
95+
uses: actions/checkout@v3
96+
with:
97+
fetch-depth: 0
98+
- name: Cache Bazel artifacts
99+
uses: actions/cache@v2
100+
with:
101+
path: |
102+
~/.cache/bazel-disk
103+
~/.cache/bazel-repo
104+
key: ${{ runner.os }}-bazel-medium-tests-${{ hashFiles('**/BUILD.bazel') }}
105+
restore-keys: |
106+
${{ runner.os }}-bazel-medium-tests-
107+
${{ runner.os }}-bazel-build-
108+
- name: Setup bazelisk
109+
uses: ./.github/actions/setup-bazelisk
110+
- name: Setup Java
111+
uses: actions/setup-java@v1
112+
with:
113+
java-version: '11'
114+
- name: Run small tests
115+
uses: ./.github/actions/bazel-test
116+
with:
117+
query: attr(size, medium, tests(//java/...)) except attr(tags, lint, tests(//java/...))
118+
89119
lint:
90120
if: ${{ needs.check_workflow.outputs.result == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(toJson(github.event.commits), '[run java]') == true }}
91121
needs: [ check_workflow, build ]

java/test/org/openqa/selenium/grid/distributor/DistributorTest.java

Lines changed: 9 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,12 @@
1717

1818
package org.openqa.selenium.grid.distributor;
1919

20-
import static org.assertj.core.api.Assertions.assertThat;
21-
import static org.assertj.core.api.Assertions.fail;
22-
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.openqa.selenium.grid.data.Availability.DOWN;
25-
import static org.openqa.selenium.grid.data.Availability.UP;
26-
import static org.openqa.selenium.remote.Dialect.W3C;
27-
2820
import com.google.common.collect.ImmutableMap;
2921
import com.google.common.collect.ImmutableSet;
3022

3123
import org.junit.After;
3224
import org.junit.Assert;
3325
import org.junit.Before;
34-
import org.junit.Ignore;
3526
import org.junit.Test;
3627
import org.openqa.selenium.Capabilities;
3728
import org.openqa.selenium.ImmutableCapabilities;
@@ -103,6 +94,12 @@
10394
import java.util.logging.Logger;
10495
import java.util.stream.Collectors;
10596

97+
import static org.assertj.core.api.Assertions.assertThat;
98+
import static org.junit.Assert.assertTrue;
99+
import static org.openqa.selenium.grid.data.Availability.DOWN;
100+
import static org.openqa.selenium.grid.data.Availability.UP;
101+
import static org.openqa.selenium.remote.Dialect.W3C;
102+
106103
public class DistributorTest {
107104

108105
private static final Logger LOG = Logger.getLogger("Distributor Test");
@@ -581,8 +578,8 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
581578
.add(massive);
582579

583580
wait.until(obj -> distributor.getStatus().getNodes().size() == 4);
584-
wait.until(ignored -> distributor.getStatus().getNodes().stream().allMatch(
585-
node -> node.getAvailability() == UP && node.hasCapacity()));
581+
wait.until(ignored -> distributor.getStatus().getNodes().stream()
582+
.allMatch(node -> node.getAvailability() == UP && node.hasCapacity()));
586583
wait.until(obj -> distributor.getStatus().hasCapacity());
587584

588585
Either<SessionNotCreatedException, CreateSessionResponse> result =
@@ -1125,6 +1122,7 @@ private Node createNode(Capabilities stereotype, int count, int currentLoad) {
11251122
for (int i = 0; i < count; i++) {
11261123
builder.add(stereotype, new TestSessionFactory((id, caps) -> new HandledSession(uri, caps)));
11271124
}
1125+
builder.maximumConcurrentSessions(12);
11281126

11291127
LocalNode node = builder.build();
11301128
for (int i = 0; i < currentLoad; i++) {
@@ -1147,77 +1145,6 @@ private Node createBrokenNode(Capabilities stereotype) {
11471145
.build();
11481146
}
11491147

1150-
@Test
1151-
@Ignore
1152-
public void shouldCorrectlySetSessionCountsWhenStartedAfterNodeWithSession() {
1153-
fail("write me!");
1154-
}
1155-
1156-
@Test
1157-
public void statusShouldIndicateThatDistributorIsNotAvailableIfNodesAreDown()
1158-
throws URISyntaxException {
1159-
Capabilities capabilities = new ImmutableCapabilities("cheese", "peas");
1160-
URI uri = new URI("http://example.com");
1161-
1162-
Node node = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
1163-
.add(
1164-
capabilities,
1165-
new TestSessionFactory((id, caps) -> new Session(id, uri, stereotype, caps, Instant.now())))
1166-
.advanced()
1167-
.healthCheck(() -> new HealthCheck.Result(DOWN, "TL;DR"))
1168-
.build();
1169-
1170-
local = new LocalDistributor(
1171-
tracer,
1172-
bus,
1173-
new PassthroughHttpClient.Factory(node),
1174-
sessions,
1175-
queue,
1176-
new DefaultSlotSelector(),
1177-
registrationSecret,
1178-
Duration.ofMinutes(5),
1179-
false,
1180-
Duration.ofSeconds(5));
1181-
1182-
local.add(node);
1183-
1184-
DistributorStatus status = local.getStatus();
1185-
assertFalse(status.hasCapacity());
1186-
}
1187-
1188-
@Test
1189-
public void disabledNodeShouldNotAcceptNewRequests()
1190-
throws URISyntaxException
1191-
{
1192-
Capabilities capabilities = new ImmutableCapabilities("cheese", "peas");
1193-
1194-
URI uri = new URI("http://example.com");
1195-
Node node = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
1196-
.add(
1197-
capabilities,
1198-
new TestSessionFactory((id, caps) -> new Session(id, uri, stereotype, caps, Instant.now())))
1199-
.advanced()
1200-
.healthCheck(() -> new HealthCheck.Result(DOWN, "TL;DR"))
1201-
.build();
1202-
1203-
local = new LocalDistributor(
1204-
tracer,
1205-
bus,
1206-
new PassthroughHttpClient.Factory(node),
1207-
sessions,
1208-
queue,
1209-
new DefaultSlotSelector(),
1210-
registrationSecret,
1211-
Duration.ofMinutes(5),
1212-
false,
1213-
Duration.ofSeconds(5));
1214-
1215-
local.add(node);
1216-
1217-
DistributorStatus status = local.getStatus();
1218-
assertFalse(status.hasCapacity());
1219-
}
1220-
12211148
@Test
12221149
public void shouldFallbackToSecondAvailableCapabilitiesIfFirstNotAvailable() {
12231150
CombinedHandler handler = new CombinedHandler();

0 commit comments

Comments
 (0)