Skip to content

Commit 44d1b49

Browse files
committed
Loading configuration from hub to node after registration (and re-registration). Fixes #374
1 parent ee4e55c commit 44d1b49

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

java/server/src/org/openqa/grid/internal/utils/SelfRegisteringRemote.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,6 @@ public SelfRegisteringRemote(RegistrationRequest request) {
7979

8080
registrationRequest.validate();
8181

82-
try {
83-
GridHubConfiguration hubConfiguration = getHubConfiguration();
84-
// the node can not set these values. They must come from the hub
85-
if (hubConfiguration.timeout != null && hubConfiguration.timeout >= 0) {
86-
registrationRequest.getConfiguration().timeout = hubConfiguration.timeout;
87-
}
88-
if (hubConfiguration.browserTimeout != null && hubConfiguration.browserTimeout >= 0) {
89-
registrationRequest.getConfiguration().browserTimeout = hubConfiguration.browserTimeout;
90-
}
91-
} catch (Exception e) {
92-
LOG.warning(
93-
"error getting the parameters from the hub. The node may end up with wrong timeouts." + e
94-
.getMessage());
95-
}
96-
9782
// add the status servlet
9883
nodeServlets.put("/status", NodeW3CStatusServlet.class);
9984
nodeServlets.put("/wd/hub/status", NodeW3CStatusServlet.class);
@@ -284,6 +269,23 @@ private void registerToHub(boolean checkPresenceFirst) {
284269
response.getStatusLine().getStatusCode(),
285270
response.getStatusLine().getReasonPhrase()));
286271
}
272+
273+
try {
274+
LOG.info("Updating the node configuration from the hub");
275+
GridHubConfiguration hubConfiguration = getHubConfiguration();
276+
// the node can not set these values. They must come from the hub
277+
if (hubConfiguration.timeout != null && hubConfiguration.timeout >= 0) {
278+
registrationRequest.getConfiguration().timeout = hubConfiguration.timeout;
279+
}
280+
if (hubConfiguration.browserTimeout != null && hubConfiguration.browserTimeout >= 0) {
281+
registrationRequest.getConfiguration().browserTimeout = hubConfiguration.browserTimeout;
282+
}
283+
} catch (Exception e) {
284+
LOG.warning(
285+
"error getting the parameters from the hub. The node may end up with wrong timeouts." + e
286+
.getMessage());
287+
}
288+
287289
LOG.info("The node is registered to the hub and ready to use");
288290
} catch (Exception e) {
289291
throw new GridException("Error sending the registration request: " + e.getMessage());

java/server/test/org/openqa/grid/e2e/misc/HubRestart.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class HubRestart {
5050
public void prepare() throws Exception {
5151
config.host = "localhost";
5252
config.port = PortProber.findFreePort();
53+
config.timeout = 10;
54+
config.browserTimeout = 10;
5355
hub = GridTestHelper.getHub(config);
5456
registry = hub.getRegistry();
5557

@@ -59,7 +61,6 @@ public void prepare() throws Exception {
5961

6062
remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
6163
remote.startRemoteServer();
62-
6364
}
6465

6566
@Test(timeout = 5000)
@@ -72,13 +73,18 @@ public void nodeRegisterAgain() throws Exception {
7273
// should be up
7374
RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
7475

76+
assertEquals(remote.getConfiguration().timeout.intValue(), 10);
77+
assertEquals(remote.getConfiguration().browserTimeout.intValue(), 10);
78+
7579
// crashing the hub.
7680
hub.stop();
7781

7882
// check that the remote do not crash if there is no hub to reply.
7983
Thread.sleep(1000);
8084

8185
// and starting a new hub
86+
config.timeout = 20;
87+
config.browserTimeout = 20;
8288
hub = new Hub(config);
8389
registry = hub.getRegistry();
8490
// should be empty
@@ -88,6 +94,8 @@ public void nodeRegisterAgain() throws Exception {
8894
// the node will appear again after 250 ms.
8995
RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
9096

97+
assertEquals(remote.getConfiguration().timeout.intValue(), 20);
98+
assertEquals(remote.getConfiguration().browserTimeout.intValue(), 20);
9199
}
92100

93101
@After

java/server/test/org/openqa/grid/e2e/utils/GridTestHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public static SelfRegisteringRemote getRemoteWithoutCapabilities(Hub hub, GridRo
4040
}
4141

4242
public static SelfRegisteringRemote getRemoteWithoutCapabilities(URL hub, GridRole role) {
43-
String[] args = {"-role", "node","-host","localhost","-hub",hub.toString(),"-port",String.valueOf(PortProber.findFreePort())};
43+
String[] args = {"-role", role.toString(),
44+
"-host","localhost",
45+
"-hub",hub.toString(),
46+
"-port",String.valueOf(PortProber.findFreePort())};
4447
GridNodeConfiguration config = new GridNodeConfiguration();
4548
new JCommander(config, args);
4649
RegistrationRequest req = RegistrationRequest.build(config);

0 commit comments

Comments
 (0)