Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #132 from zalando/release-instances
Browse files Browse the repository at this point in the history
Fixes for #131 and #123
  • Loading branch information
diemol authored May 31, 2017
2 parents 42e027b + dbf1654 commit a8f2cf0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
<properties>
<selenium-server.major-minor.version>3.3</selenium-server.major-minor.version>
<selenium-server.patch-level.version>1</selenium-server.patch-level.version>
<docker-client.version>8.4.0</docker-client.version>
<docker-client.version>8.6.0</docker-client.version>
<junit.version>4.12</junit.version>
<mockito.version>2.7.22</mockito.version>
<mockito.version>2.8.9</mockito.version>
<awaitility.version>3.0.0</awaitility.version>
<testng.version>6.11</testng.version>
<slf4j.version>1.7.25</slf4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ public void executeCommand(String containerId, String[] command) {
DockerClient.ExecCreateParam.attachStdout(), DockerClient.ExecCreateParam.attachStderr());
final LogStream output = dockerClient.execStart(execCreation.id());
logger.log(Level.INFO, () -> String.format("%s %s", nodeId, Arrays.toString(command)));
logger.log(Level.INFO, () -> String.format("%s %s", nodeId, output.readFully()));
try {
logger.log(Level.INFO, () -> String.format("%s %s", nodeId, output.readFully()));
} catch (Exception e) {
logger.log(Level.FINE, nodeId + " Error while executing the output.readFully()", e);
ga.trackException(e);
}
} catch (DockerException | InterruptedException e) {
logger.log(Level.WARNING, nodeId + " Error while executing the command", e);
logger.log(Level.FINE, nodeId + " Error while executing the command", e);
ga.trackException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public TestInformation getTestInformation(String seleniumSessionId) {
JsonObject testData = getCommonProxyUtilities().readJSONFromUrl(browserStackTestUrl, BROWSER_STACK_USER,
BROWSER_STACK_KEY).getAsJsonObject();
JsonObject automation_session = testData.getAsJsonObject("automation_session");
String testName = automation_session.get("name").getAsString();
String testName = automation_session.get("name").isJsonNull() ? null : automation_session.get("name").getAsString();
String browser = automation_session.get("browser").getAsString();
String browserVersion = automation_session.get("browser_version").getAsString();
String platform = automation_session.get("os").getAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public class DockerSeleniumRemoteProxy extends DefaultRemoteProxy {
private static final Environment defaultEnvironment = new Environment();
private static boolean videoRecordingEnabled;
private static Environment env = defaultEnvironment;
private static ContainerClient defaultContainerClient = ContainerFactory.getContainerClient();
private static ContainerClient containerClient = defaultContainerClient;
private ContainerClient containerClient = ContainerFactory.getContainerClient();
private final HtmlRenderer renderer = new WebProxyHtmlRendererBeta(this);
private int amountOfExecutedTests;
private long maxTestIdleTimeSecs;
Expand Down Expand Up @@ -83,13 +82,18 @@ static void readEnvVarForVideoRecording() {
}

@VisibleForTesting
static void setContainerClient(final ContainerClient client) {
ContainerClient getContainerClient() {
return containerClient;
}

@VisibleForTesting
void setContainerClient(final ContainerClient client) {
containerClient = client;
}

@VisibleForTesting
static void restoreContainerClient() {
containerClient = defaultContainerClient;
void restoreContainerClient() {
containerClient = ContainerFactory.getContainerClient();
}

@VisibleForTesting
Expand Down Expand Up @@ -162,10 +166,11 @@ public CapabilityMatcher getCapabilityHelper() {
private long getConfiguredIdleTimeout(Map<String, Object> requestedCapability) {
long configuredIdleTimeout;
try {
configuredIdleTimeout = (long) requestedCapability.getOrDefault("idleTimeout", DEFAULT_MAX_TEST_IDLE_TIME_SECS);
Object idleTimeout = requestedCapability.getOrDefault("idleTimeout", DEFAULT_MAX_TEST_IDLE_TIME_SECS);
configuredIdleTimeout = Long.valueOf(String.valueOf(idleTimeout));
} catch (Exception e) {
configuredIdleTimeout = DEFAULT_MAX_TEST_IDLE_TIME_SECS;
LOGGER.log(Level.FINE, getId() + " " + e.toString(), e);
LOGGER.log(Level.WARNING, getId() + " " + e.toString(), e);
}
if (configuredIdleTimeout <= 0) {
configuredIdleTimeout = DEFAULT_MAX_TEST_IDLE_TIME_SECS;
Expand Down Expand Up @@ -449,7 +454,7 @@ private void shutdownNode(boolean isTestIdle) {
}

try {
containerClient.stopContainer(dockerSeleniumRemoteProxy.getContainerId());
dockerSeleniumRemoteProxy.getContainerClient().stopContainer(dockerSeleniumRemoteProxy.getContainerId());
} catch (Exception e) {
LOGGER.log(Level.SEVERE, dockerSeleniumRemoteProxy.getId() + " " + e.getMessage(), e);
dockerSeleniumRemoteProxy.ga.trackException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public TestInformation getTestInformation(String seleniumSessionId) {
for (int i = 0; i < 5; i++) {
JsonObject testData = getCommonProxyUtilities().readJSONFromUrl(testingBotTestUrl, TESTINGBOT_KEY,
TESTINGBOT_SECRET).getAsJsonObject();
String testName = testData.get("name").getAsString();
String testName = testData.get("name").isJsonNull() ? null : testData.get("name").getAsString();
String browser = testData.get("browser").getAsString();
String browserVersion = testData.get("browser_version").getAsString();
String platform = testData.get("os").getAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public void setUp() throws DockerException, InterruptedException, IOException {
// Creating the proxy
proxy = DockerSeleniumRemoteProxy.getNewInstance(request, registry);

DockerSeleniumRemoteProxy.setContainerClient(containerClient);
proxy.setContainerClient(containerClient);
}

@After
public void tearDown() {
DockerSeleniumRemoteProxy.restoreContainerClient();
proxy.restoreContainerClient();
}

@Test
Expand Down Expand Up @@ -147,6 +147,15 @@ public void testIdleTimeoutUsesDefaultValueWhenCapabilityHasFaultyValue() {
Assert.assertEquals(proxy.getMaxTestIdleTimeSecs(), DockerSeleniumRemoteProxy.DEFAULT_MAX_TEST_IDLE_TIME_SECS);
}

@Test
public void testIdleTimeoutUsesValueInStringPassedAsCapability() {
Map<String, Object> requestedCapability = getCapabilitySupportedByDockerSelenium();
requestedCapability.put("idleTimeout", "200");

proxy.getNewSession(requestedCapability);
Assert.assertEquals(proxy.getMaxTestIdleTimeSecs(), 200L);
}

@Test
public void testIdleTimeoutUsesValuePassedAsCapability() {
Map<String, Object> requestedCapability = getCapabilitySupportedByDockerSelenium();
Expand Down

0 comments on commit a8f2cf0

Please sign in to comment.