Skip to content

Commit 44a4191

Browse files
committed
[grid] Code formatting and removing two tests
The removed tests were trying to assert that a Node can only register to the Distributor when they provide the correct registration secret. However, they were using the `GuavaEventBus`, which does not have the logic that compares secrets. So testing this here is pointless, in addition, the test was flaky due to a race condition. Moreover, testing that all events have a valid secret is already being done here https://github.com/SeleniumHQ/selenium/blob/trunk/java/server/test/org/openqa/selenium/events/ZeroMqEventBusTest.java#L36
1 parent 5c51316 commit 44a4191

File tree

1 file changed

+44
-87
lines changed

1 file changed

+44
-87
lines changed

java/server/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java

+44-87
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,19 @@ public void setUpDistributor() throws MalformedURLException {
121121

122122
stereotype = new ImmutableCapabilities("browserName", "gouda");
123123

124-
wait = new FluentWait<>(new Object()).ignoring(Throwable.class).withTimeout(Duration.ofSeconds(2));
124+
wait = new FluentWait<>(
125+
new Object()).ignoring(Throwable.class).withTimeout(Duration.ofSeconds(2));
125126
}
126127

127128
@Test
128129
public void shouldBeAbleToRegisterALocalNode() throws URISyntaxException {
129130
URI sessionUri = new URI("http://example:1234");
130-
Node node = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
131-
.add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
131+
Node node = LocalNode
132+
.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
133+
.add(
134+
CAPS,
135+
new TestSessionFactory(
136+
(id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
132137
.build();
133138
handler.addHandler(node);
134139

@@ -140,86 +145,15 @@ public void shouldBeAbleToRegisterALocalNode() throws URISyntaxException {
140145
assertEquals(1, getStereotypes(status).get(CAPS).intValue());
141146
}
142147

143-
@Test
144-
public void shouldNotRegisterALocalNodeWithWrongRegistrationSecret() throws URISyntaxException {
145-
URI sessionUri = new URI("http://example:1234");
146-
HttpClient.Factory clientFactory = new RoutableHttpClientFactory(
147-
externalUrl,
148-
handler,
149-
HttpClient.Factory.createDefault());
150-
151-
Secret registrationSecret = new Secret("my_secret");
152-
153-
Node node = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
154-
.add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
155-
.build();
156-
handler.addHandler(node);
157-
158-
LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
159-
LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(
160-
tracer,
161-
bus,
162-
Duration.ofSeconds(2),
163-
Duration.ofSeconds(2));
164-
LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(tracer, bus, localNewSessionQueue);
165-
Distributor secretDistributor = new LocalDistributor(
166-
tracer,
167-
bus,
168-
clientFactory,
169-
sessions,
170-
queuer,
171-
registrationSecret);
172-
173-
bus.fire(new NodeStatusEvent(node.getStatus()));
174-
175-
assertEquals(0, secretDistributor.getAvailableNodes().size());
176-
}
177-
178-
@Test
179-
public void shouldRegisterALocalNodeWithCorrectRegistrationSecret() throws URISyntaxException {
180-
URI sessionUri = new URI("http://example:1234");
181-
HttpClient.Factory clientFactory = new RoutableHttpClientFactory(
182-
externalUrl,
183-
handler,
184-
HttpClient.Factory.createDefault());
185-
186-
Secret registrationSecret = new Secret("my_secret");
187-
188-
Node node = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
189-
.add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
190-
.build();
191-
handler.addHandler(node);
192-
193-
LocalSessionMap sessions = new LocalSessionMap(tracer, bus);
194-
LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue(
195-
tracer,
196-
bus,
197-
Duration.ofSeconds(2),
198-
Duration.ofSeconds(2));
199-
LocalNewSessionQueuer queuer = new LocalNewSessionQueuer(tracer, bus, localNewSessionQueue);
200-
Distributor secretDistributor = new LocalDistributor(
201-
tracer,
202-
bus,
203-
clientFactory,
204-
sessions,
205-
queuer,
206-
registrationSecret);
207-
208-
bus.fire(new NodeStatusEvent(node.getStatus()));
209-
210-
wait.until(obj -> secretDistributor.getStatus().hasCapacity());
211-
212-
assertEquals(1, secretDistributor.getAvailableNodes().size());
213-
}
214-
215148
@Test
216149
public void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {
217150
URI sessionUri = new URI("http://example:1234");
218151
Node node = new CustomNode(
219152
bus,
220153
new NodeId(UUID.randomUUID()),
221154
externalUrl.toURI(),
222-
c -> new Session(new SessionId(UUID.randomUUID()), sessionUri, stereotype, c, Instant.now()));
155+
c -> new Session(
156+
new SessionId(UUID.randomUUID()), sessionUri, stereotype, c, Instant.now()));
223157
handler.addHandler(node);
224158

225159
distributor.add(node);
@@ -233,8 +167,12 @@ public void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {
233167
@Test
234168
public void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxException {
235169
URI sessionUri = new URI("http://example:1234");
236-
Node node = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
237-
.add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
170+
Node node = LocalNode
171+
.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
172+
.add(
173+
CAPS,
174+
new TestSessionFactory(
175+
(id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
238176
.build();
239177
handler.addHandler(node);
240178

@@ -247,13 +185,22 @@ public void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxEx
247185
}
248186

249187
@Test
250-
public void shouldKeepOnlyOneNodeWhenTwoRegistrationsHaveTheSameUriByListeningForEvents() throws URISyntaxException {
188+
public void shouldKeepOnlyOneNodeWhenTwoRegistrationsHaveTheSameUriByListeningForEvents()
189+
throws URISyntaxException {
251190
URI sessionUri = new URI("http://example:1234");
252-
Node firstNode = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
253-
.add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
191+
Node firstNode = LocalNode
192+
.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
193+
.add(
194+
CAPS,
195+
new TestSessionFactory(
196+
(id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
254197
.build();
255-
Node secondNode = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
256-
.add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
198+
Node secondNode = LocalNode
199+
.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
200+
.add(
201+
CAPS,
202+
new TestSessionFactory(
203+
(id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
257204
.build();
258205
handler.addHandler(firstNode);
259206
handler.addHandler(secondNode);
@@ -272,8 +219,12 @@ public void shouldKeepOnlyOneNodeWhenTwoRegistrationsHaveTheSameUriByListeningFo
272219
public void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChange()
273220
throws URISyntaxException {
274221
URI sessionUri = new URI("http://example:1234");
275-
Node node = LocalNode.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
276-
.add(CAPS, new TestSessionFactory((id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
222+
Node node = LocalNode
223+
.builder(tracer, bus, externalUrl.toURI(), externalUrl.toURI(), registrationSecret)
224+
.add(
225+
CAPS,
226+
new TestSessionFactory(
227+
(id, caps) -> new Session(id, sessionUri, stereotype, caps, Instant.now())))
277228
.build();
278229
handler.addHandler(node);
279230

@@ -296,7 +247,8 @@ public void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChan
296247
new SlotId(status.getId(), UUID.randomUUID()),
297248
CAPS,
298249
Instant.now(),
299-
Optional.of(new Session(new SessionId(UUID.randomUUID()), sessionUri, CAPS, CAPS, Instant.now())))),
250+
Optional.of(new Session(
251+
new SessionId(UUID.randomUUID()), sessionUri, CAPS, CAPS, Instant.now())))),
300252
UP);
301253

302254
bus.fire(new NodeStatusEvent(crafted));
@@ -396,7 +348,12 @@ public NodeStatus getStatus() {
396348
Session sess = null;
397349
if (running != null) {
398350
try {
399-
sess = new Session(running.getId(), new URI("http://localhost:14568"), CAPS, running.getCapabilities(), Instant.now());
351+
sess = new Session(
352+
running.getId(),
353+
new URI("http://localhost:14568"),
354+
CAPS,
355+
running.getCapabilities(),
356+
Instant.now());
400357
} catch (URISyntaxException e) {
401358
throw new RuntimeException(e);
402359
}

0 commit comments

Comments
 (0)