Skip to content

Commit 670c42f

Browse files
committed
adding grid e2e distribution test
1 parent 185755a commit 670c42f

File tree

2 files changed

+130
-2
lines changed

2 files changed

+130
-2
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.grid.e2e.misc;
19+
20+
import junit.framework.Assert;
21+
22+
import org.junit.AfterClass;
23+
import org.junit.BeforeClass;
24+
import org.junit.Test;
25+
import org.openqa.grid.common.GridRole;
26+
import org.openqa.grid.e2e.utils.GridTestHelper;
27+
import org.openqa.grid.e2e.utils.RegistryTestHelper;
28+
import org.openqa.grid.internal.ProxySet;
29+
import org.openqa.grid.internal.RemoteProxy;
30+
import org.openqa.grid.internal.TestSlot;
31+
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
32+
import org.openqa.grid.web.Hub;
33+
import org.openqa.selenium.WebDriver;
34+
import org.openqa.selenium.remote.DesiredCapabilities;
35+
import org.openqa.selenium.server.SeleniumServer;
36+
37+
import java.util.ArrayList;
38+
import java.util.List;
39+
40+
public class GridDistributionTest {
41+
42+
private static Hub hub;
43+
private static List<WebDriver> drivers = new ArrayList<>();
44+
45+
@BeforeClass
46+
public static void prepare() throws Exception {
47+
48+
hub = GridTestHelper.getHub();
49+
50+
for (int i =0; i < 8; i++) {
51+
SelfRegisteringRemote remote =
52+
GridTestHelper.getRemoteWithoutCapabilities(hub, GridRole.NODE);
53+
54+
remote.addBrowser(DesiredCapabilities.chrome(), 3);
55+
remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
56+
remote.startRemoteServer();
57+
remote.sendRegistrationRequest();
58+
RegistryTestHelper.waitForNode(hub.getRegistry(), i+1);
59+
}
60+
}
61+
62+
@Test
63+
public void testLoadIsDistributedEvenly() throws Throwable {
64+
65+
66+
for (int i=0; i < 8; i++) {
67+
drivers.add(GridTestHelper.getRemoteWebDriver(DesiredCapabilities.chrome(), hub));
68+
}
69+
70+
ProxySet ps = hub.getRegistry().getAllProxies();
71+
72+
for (RemoteProxy p : ps) {
73+
int freeslots = 0;
74+
for (TestSlot ts : p.getTestSlots()) {
75+
if (ts.getSession() == null) {
76+
freeslots++;
77+
}
78+
}
79+
Assert.assertEquals("checking proxy free slots, all should have only one session running", freeslots, 2);
80+
}
81+
82+
for (int i=0; i < 8; i++) {
83+
drivers.add(GridTestHelper.getRemoteWebDriver(DesiredCapabilities.chrome(), hub));
84+
}
85+
86+
for (RemoteProxy p : ps) {
87+
int freeslots = 0;
88+
for (TestSlot ts : p.getTestSlots()) {
89+
if (ts.getSession() == null) {
90+
freeslots++;
91+
}
92+
}
93+
Assert.assertEquals("checking proxy free slots, all should have two sessions running", freeslots, 1);
94+
}
95+
96+
drivers.add(GridTestHelper.getRemoteWebDriver(DesiredCapabilities.chrome(), hub));
97+
98+
Boolean foundOneFull = false;
99+
for (RemoteProxy p : ps) {
100+
int freeslots = 0;
101+
for (TestSlot ts : p.getTestSlots()) {
102+
if (ts.getSession() == null) {
103+
freeslots++;
104+
}
105+
}
106+
if (freeslots == 0) {
107+
if (!foundOneFull) {
108+
foundOneFull = true;
109+
} else {
110+
throw new RuntimeException(
111+
"Found more than one node with all test slots running sessions");
112+
}
113+
}
114+
}
115+
}
116+
117+
@AfterClass
118+
public static void stop() throws Exception {
119+
for (WebDriver driver : drivers) {
120+
try {
121+
driver.quit();
122+
} catch (Exception e) {
123+
System.out.println(e.toString());
124+
}
125+
}
126+
hub.stop();
127+
}
128+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public static Hub getHub(GridHubConfiguration config) throws Exception {
9292
return hub;
9393
}
9494

95-
public static void getRemoteWebDriver(DesiredCapabilities caps, Hub hub)
95+
public static RemoteWebDriver getRemoteWebDriver(DesiredCapabilities caps, Hub hub)
9696
throws MalformedURLException {
97-
new RemoteWebDriver(getGridDriver(hub), caps);
97+
return new RemoteWebDriver(getGridDriver(hub), caps);
9898
}
9999

100100
public static URL getGridDriver(Hub hub) throws MalformedURLException {

0 commit comments

Comments
 (0)