Skip to content

Commit

Permalink
[grid] Extra test to ensure session urls are correct
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jan 25, 2019
1 parent 3c528a0 commit 080a3ce
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions java/server/test/org/openqa/selenium/grid/node/NodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.openqa.selenium.remote.http.HttpMethod.GET;
import static org.openqa.selenium.remote.http.HttpMethod.POST;

import com.google.common.collect.ImmutableSet;
Expand All @@ -45,6 +46,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
Expand Down Expand Up @@ -301,6 +303,60 @@ public void shouldNotPropagateExceptionsWhenSessionCreationFails() {
assertThat(session.isPresent()).isFalse();
}

@Test
public void eachSessionShouldReportTheNodesUrl() throws URISyntaxException {
URI sessionUri = new URI("http://cheese:42/peas");
Node node = LocalNode.builder(tracer, clientFactory, uri, sessions)
.add(caps, c -> new Session(new SessionId(UUID.randomUUID()), sessionUri, c))
.build();
Optional<Session> session = node.newSession(caps);
assertThat(session.isPresent()).isTrue();
assertThat(session.get().getUri()).isEqualTo(uri);
}

@Test
public void sendingAMessageToASessionGetsItRoutedToTheCorrectActualHandler()
throws URISyntaxException {
URI sessionUri = new URI("http://cheese:42/peas");

AtomicBoolean called = new AtomicBoolean(false);
AtomicReference<URL> clientUrl = new AtomicReference<>();

HttpClient.Factory factory = new HttpClient.Factory() {
@Override
public HttpClient.Builder builder() {
return new HttpClient.Builder() {
@Override
public HttpClient createClient(URL url) {
clientUrl.set(url);
return request -> {
called.set(true);
return new HttpResponse();
};
}
};
}

@Override
public void cleanupIdleClients() {
// no-op
}
};

Node node = LocalNode.builder(tracer, factory, uri, sessions)
.add(caps, c -> new Session(new SessionId(UUID.randomUUID()), sessionUri, c))
.build();

Session session = node.newSession(caps).orElseThrow(() -> new AssertionError("No session"));

node.executeWebDriverCommand(
new HttpRequest(GET, String.format("/session/%s/url", session.getId())),
new HttpResponse());

assertThat(clientUrl.get().toURI()).isEqualTo(sessionUri);
assertThat(called.get()).isTrue();
}

private static class MyClock extends Clock {

private final AtomicReference<Instant> now;
Expand Down

0 comments on commit 080a3ce

Please sign in to comment.