Skip to content

Commit

Permalink
Checking a node status when attempting to create a new session. This
Browse files Browse the repository at this point in the history
allows to skip unavailable nodes. In theory a dead node should be removed
from the list after 30s timeout but for some reason this does not happen,
it's another issue. Fixes issue 1873
  • Loading branch information
barancev committed May 5, 2013
1 parent 3e5e765 commit 2edd481
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 29 deletions.
6 changes: 6 additions & 0 deletions java/server/src/org/openqa/grid/internal/BaseRemoteProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ public URL getRemoteHost() {

public TestSession getNewSession(Map<String, Object> requestedCapability) {
log.info("Trying to create a new session on node " + this);
try {
getStatus();
} catch (GridException ex) {
log.info("Node " + this + " is down or doesn't recognize the /wd/hub/status request");
return null;
}
if (!hasCapability(requestedCapability)) {
log.info("Node " + this + " has no matching capability");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static void prepare() throws Exception {
remote.addBrowser(ff7, 1);
remote.addBrowser(ff3, 1);

remote.startRemoteServer();
remote.sendRegistrationRequest();
}

Expand Down Expand Up @@ -103,6 +104,7 @@ public void firefoxOnWebDriver() throws MalformedURLException {

@AfterClass
public static void teardown() throws Exception {
remote.stopRemoteServer();
hub.stop();
}

Expand Down
35 changes: 35 additions & 0 deletions java/server/test/org/openqa/grid/internal/DetachedRemoteProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2013 Selenium committers
Copyright 2013 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.openqa.grid.internal;

import org.json.JSONObject;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.exception.GridException;

public class DetachedRemoteProxy extends BaseRemoteProxy {

public DetachedRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
}

@Override
public JSONObject getStatus() throws GridException {
return null; // just to make sure there is no GridException thrown
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void setup() {
private static void register5ProxiesOf5Slots() {
// add 5 proxies. Total = 5 proxies * 5 slots each = 25 firefox.
for (int i = 0; i < 5; i++) {
registry.add(new BaseRemoteProxy(getRequestOfNSlots(5, "name" + i), registry));
registry.add(new DetachedRemoteProxy(getRequestOfNSlots(5, "name" + i), registry));
}
}

Expand All @@ -68,9 +68,9 @@ private static void register5ProxiesOf5Slots() {
// proxy 2 -> 4 slots
// proxy 3 -> 6 slots
private static void register3ProxiesVariableSlotSize() {
proxy1 = new BaseRemoteProxy(getRequestOfNSlots(2, "proxy1"), registry2);
proxy2 = new BaseRemoteProxy(getRequestOfNSlots(4, "proxy2"), registry2);
proxy3 = new BaseRemoteProxy(getRequestOfNSlots(6, "proxy3"), registry2);
proxy1 = new DetachedRemoteProxy(getRequestOfNSlots(2, "proxy1"), registry2);
proxy2 = new DetachedRemoteProxy(getRequestOfNSlots(4, "proxy2"), registry2);
proxy3 = new DetachedRemoteProxy(getRequestOfNSlots(6, "proxy3"), registry2);

registry2.add(proxy1);
registry2.add(proxy2);
Expand Down
12 changes: 7 additions & 5 deletions java/server/test/org/openqa/grid/internal/ParallelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openqa.grid.internal.mock.GridHelper;
import org.openqa.grid.internal.mock.MockedRequestHandler;
import org.openqa.grid.web.servlet.handler.RequestHandler;
import org.openqa.selenium.remote.CapabilityType;

public class ParallelTest {

Expand Down Expand Up @@ -68,7 +69,7 @@ public static void prepareReqRequest() {
@Test
public void canGetApp2() {
Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);
try {
registry.add(p1);
RequestHandler newSessionRequest = GridHelper.createNewSessionHandler(registry, app2);
Expand All @@ -89,7 +90,7 @@ public void canGetApp2() {
@Test
public void cannotGet2App2() throws InterruptedException {
final Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);
try {
registry.add(p1);
MockedRequestHandler newSessionRequest = GridHelper.createNewSessionHandler(registry, app2);
Expand Down Expand Up @@ -117,7 +118,7 @@ public void run() {
@Test(timeout = 2000)
public void canGet5App1() {
final Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);
try {
registry.add(p1);
for (int i = 0; i < 5; i++) {
Expand All @@ -138,7 +139,7 @@ public void canGet5App1() {
@Test(timeout = 1000)
public void cannotGet6App1() throws InterruptedException {
final Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);
try {
registry.add(p1);
final AtomicInteger count = new AtomicInteger();
Expand Down Expand Up @@ -176,7 +177,7 @@ static synchronized void inc2() {
@Test(timeout = 1000)
public void cannotGetApp2() throws InterruptedException {
final Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);
try {
registry.add(p1);

Expand Down Expand Up @@ -227,6 +228,7 @@ public void releaseAndReserve() {
req.addDesiredCapability(app1);
req.addDesiredCapability(app2);
req.setConfiguration(config);
req.getConfiguration().put(CapabilityType.PROXY, DetachedRemoteProxy.class.getCanonicalName());

p1 = BaseRemoteProxy.getNewInstance(req, registry);

Expand Down
13 changes: 7 additions & 6 deletions java/server/test/org/openqa/grid/internal/RegistryStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.exception.GridException;
import org.openqa.grid.internal.mock.GridHelper;
import org.openqa.grid.internal.mock.MockedRequestHandler;
import org.openqa.grid.web.servlet.handler.RequestHandler;
Expand Down Expand Up @@ -69,7 +71,7 @@ public static void prepareReqRequest() {
public void sessionIsRemoved() {
Registry registry = Registry.newInstance();

RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);


try {
Expand All @@ -89,7 +91,7 @@ public void sessionIsRemoved() {
@Test(timeout = 5000)
public void basichecks() {
Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);

try {
registry.add(p1);
Expand Down Expand Up @@ -118,7 +120,7 @@ public void basichecks() {
@Test(timeout = 4000)
public void sessionIsRemoved2() {
Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);

try {
registry.add(p1);
Expand All @@ -137,7 +139,7 @@ public void sessionIsRemoved2() {
@Test(timeout = 4000)
public void sessionByExtKey() {
Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);

try {
registry.add(p1);
Expand Down Expand Up @@ -166,7 +168,7 @@ public void sessionByExtKey() {
@Test
public void sessionByExtKeyNull() {
Registry registry = Registry.newInstance();
RemoteProxy p1 = new BaseRemoteProxy(req, registry);
RemoteProxy p1 = new DetachedRemoteProxy(req, registry);

try {
registry.add(p1);
Expand All @@ -183,5 +185,4 @@ public void sessionByExtKeyNull() {
registry.stop();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.exception.GridException;
import org.openqa.selenium.remote.DesiredCapabilities;

@SuppressWarnings({"JavaDoc"})
Expand Down Expand Up @@ -98,7 +100,7 @@ public static RemoteProxy getNewBasicRemoteProxy(List<Map<String, Object>> caps,
}

private static RemoteProxy createProxy(Registry registry, RegistrationRequest req) {
final RemoteProxy remoteProxy = new BaseRemoteProxy(req, registry);
final RemoteProxy remoteProxy = new DetachedRemoteProxy(req, registry);
remoteProxy.setupTimeoutListener();
return remoteProxy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.exception.GridException;
import org.openqa.grid.internal.listeners.TimeoutListener;
import org.openqa.grid.internal.mock.GridHelper;
import org.openqa.grid.web.servlet.handler.RequestHandler;
Expand Down Expand Up @@ -59,7 +61,7 @@ public static void setup() {
req.setConfiguration(config);
}

class MyRemoteProxyTimeout extends BaseRemoteProxy implements TimeoutListener {
class MyRemoteProxyTimeout extends DetachedRemoteProxy implements TimeoutListener {

public MyRemoteProxyTimeout(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down Expand Up @@ -100,7 +102,7 @@ public void testTimeout() throws InterruptedException {

private static boolean timeoutDone = false;

class MyRemoteProxyTimeoutSlow extends BaseRemoteProxy implements TimeoutListener {
class MyRemoteProxyTimeoutSlow extends DetachedRemoteProxy implements TimeoutListener {

public MyRemoteProxyTimeoutSlow(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand All @@ -114,7 +116,6 @@ public void beforeRelease(TestSession session) {
e.printStackTrace();
}
}

}

@Test(timeout = 5000)
Expand Down Expand Up @@ -156,7 +157,7 @@ public void testTimeoutSlow() throws InterruptedException {
}
}

class MyBuggyRemoteProxyTimeout extends BaseRemoteProxy implements TimeoutListener {
class MyBuggyRemoteProxyTimeout extends DetachedRemoteProxy implements TimeoutListener {

public MyBuggyRemoteProxyTimeout(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down Expand Up @@ -199,7 +200,7 @@ public void run() {
}
}

class MyStupidConfig extends BaseRemoteProxy implements TimeoutListener {
class MyStupidConfig extends DetachedRemoteProxy implements TimeoutListener {

public MyStupidConfig(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.BaseRemoteProxy;
import org.openqa.grid.internal.DetachedRemoteProxy;
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.TestSession;
import org.openqa.grid.internal.listeners.RegistrationListener;
Expand All @@ -39,7 +40,7 @@ public class RegistrationListenerTest {

private static boolean serverUp = false;

static class MyRemoteProxy extends BaseRemoteProxy implements RegistrationListener {
static class MyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {

public MyRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down Expand Up @@ -88,7 +89,7 @@ public void testRegistration() {
*
* @author François Reynaud
*/
static class MyBuggyRemoteProxy extends BaseRemoteProxy implements RegistrationListener {
static class MyBuggyRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {

public MyBuggyRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down Expand Up @@ -118,7 +119,7 @@ public void testBugRegistration() {

static boolean slowRemoteUp = false;

static class MySlowRemoteProxy extends BaseRemoteProxy implements RegistrationListener {
static class MySlowRemoteProxy extends DetachedRemoteProxy implements RegistrationListener {

public MySlowRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand All @@ -144,7 +145,7 @@ public void beforeRegistration() {
public void registerSomeSlow() {
final Registry registry = Registry.newInstance();
try {
registry.add(new BaseRemoteProxy(req, registry));
registry.add(new DetachedRemoteProxy(req, registry));
new Thread(new Runnable() { // Thread safety reviewed
public void run() {
registry.add(new MySlowRemoteProxy(req, registry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.DetachedRemoteProxy;
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.BaseRemoteProxy;
import org.openqa.grid.internal.SessionTerminationReason;
Expand All @@ -43,7 +44,7 @@

public class SessionListenerTest {

static class MyRemoteProxy extends BaseRemoteProxy implements TestSessionListener {
static class MyRemoteProxy extends DetachedRemoteProxy implements TestSessionListener {

public MyRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down Expand Up @@ -97,7 +98,7 @@ public void beforeAfterRan() {
*
* @author Francois Reynaud
*/
static class MyBuggyBeforeRemoteProxy extends BaseRemoteProxy implements TestSessionListener {
static class MyBuggyBeforeRemoteProxy extends DetachedRemoteProxy implements TestSessionListener {

private boolean firstCall = true;

Expand Down Expand Up @@ -153,7 +154,7 @@ public void buggyBefore() throws InterruptedException {
*
* @author Francois Reynaud
*/
static class MyBuggyAfterRemoteProxy extends BaseRemoteProxy implements TestSessionListener {
static class MyBuggyAfterRemoteProxy extends DetachedRemoteProxy implements TestSessionListener {

public MyBuggyAfterRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand Down Expand Up @@ -206,7 +207,7 @@ public void run() {
}
}

class SlowAfterSession extends BaseRemoteProxy implements TestSessionListener, TimeoutListener {
class SlowAfterSession extends DetachedRemoteProxy implements TestSessionListener, TimeoutListener {

private Lock lock = new ReentrantLock();
private boolean firstTime = true;
Expand Down

0 comments on commit 2edd481

Please sign in to comment.