92
92
93
93
import static org .assertj .core .api .Assertions .assertThat ;
94
94
import static org .assertj .core .api .Assertions .fail ;
95
+ import static org .assertj .core .api .Assertions .from ;
95
96
import static org .junit .Assert .assertFalse ;
96
97
import static org .junit .Assert .assertTrue ;
97
98
import static org .openqa .selenium .grid .data .Availability .DOWN ;
@@ -110,6 +111,8 @@ public class DistributorTest {
110
111
private Capabilities caps ;
111
112
private URI nodeUri ;
112
113
private URI routableUri ;
114
+ private LocalSessionMap sessions ;
115
+ private NewSessionQueue queue ;
113
116
114
117
private static <A , B > EitherAssert <A , B > assertThatEither (Either <A , B > either ) {
115
118
return new EitherAssert <>(either );
@@ -121,14 +124,21 @@ public void setUp() throws URISyntaxException {
121
124
routableUri = createUri ();
122
125
tracer = DefaultTestTracer .createTracer ();
123
126
bus = new GuavaEventBus ();
124
- LocalSessionMap sessions = new LocalSessionMap (tracer , bus );
125
- NewSessionQueue queue = new LocalNewSessionQueue (
127
+ sessions = new LocalSessionMap (tracer , bus );
128
+ queue = new LocalNewSessionQueue (
126
129
tracer ,
127
130
bus ,
128
131
new DefaultSlotMatcher (),
129
132
Duration .ofSeconds (2 ),
130
133
Duration .ofSeconds (2 ),
131
134
registrationSecret );
135
+
136
+ stereotype = new ImmutableCapabilities ("browserName" , "cheese" );
137
+ caps = new ImmutableCapabilities ("browserName" , "cheese" );
138
+ }
139
+
140
+ @ Test
141
+ public void creatingANewSessionWithoutANodeEndsInFailure () {
132
142
local = new LocalDistributor (
133
143
tracer ,
134
144
bus ,
@@ -139,12 +149,6 @@ public void setUp() throws URISyntaxException {
139
149
registrationSecret ,
140
150
Duration .ofMinutes (5 ),
141
151
false );
142
- stereotype = new ImmutableCapabilities ("browserName" , "cheese" );
143
- caps = new ImmutableCapabilities ("browserName" , "cheese" );
144
- }
145
-
146
- @ Test
147
- public void creatingANewSessionWithoutANodeEndsInFailure () {
148
152
Either <SessionNotCreatedException , CreateSessionResponse > result = local .newSession (createRequest (caps ));
149
153
assertThatEither (result ).isLeft ();
150
154
}
@@ -509,6 +513,17 @@ public void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime() {
509
513
new TestSessionFactory ((id , c ) -> new Session (id , nodeUri , stereotype , c , Instant .now ())))
510
514
.build ();
511
515
516
+ local = new LocalDistributor (
517
+ tracer ,
518
+ bus ,
519
+ new PassthroughHttpClient .Factory (node ),
520
+ sessions ,
521
+ queue ,
522
+ new DefaultSlotSelector (),
523
+ registrationSecret ,
524
+ Duration .ofMinutes (5 ),
525
+ false );
526
+
512
527
local .add (node );
513
528
local .add (node );
514
529
@@ -1077,6 +1092,17 @@ public void statusShouldIndicateThatDistributorIsNotAvailableIfNodesAreDown()
1077
1092
.healthCheck (() -> new HealthCheck .Result (DOWN , "TL;DR" ))
1078
1093
.build ();
1079
1094
1095
+ local = new LocalDistributor (
1096
+ tracer ,
1097
+ bus ,
1098
+ new PassthroughHttpClient .Factory (node ),
1099
+ sessions ,
1100
+ queue ,
1101
+ new DefaultSlotSelector (),
1102
+ registrationSecret ,
1103
+ Duration .ofMinutes (5 ),
1104
+ false );
1105
+
1080
1106
local .add (node );
1081
1107
1082
1108
DistributorStatus status = local .getStatus ();
@@ -1098,6 +1124,17 @@ public void disabledNodeShouldNotAcceptNewRequests()
1098
1124
.healthCheck (() -> new HealthCheck .Result (DOWN , "TL;DR" ))
1099
1125
.build ();
1100
1126
1127
+ local = new LocalDistributor (
1128
+ tracer ,
1129
+ bus ,
1130
+ new PassthroughHttpClient .Factory (node ),
1131
+ sessions ,
1132
+ queue ,
1133
+ new DefaultSlotSelector (),
1134
+ registrationSecret ,
1135
+ Duration .ofMinutes (5 ),
1136
+ false );
1137
+
1101
1138
local .add (node );
1102
1139
1103
1140
DistributorStatus status = local .getStatus ();
@@ -1106,8 +1143,27 @@ public void disabledNodeShouldNotAcceptNewRequests()
1106
1143
1107
1144
@ Test
1108
1145
public void shouldFallbackToSecondAvailableCapabilitiesIfFirstNotAvailable () {
1109
- local .add (createNode (new ImmutableCapabilities ("browserName" , "not cheese" ), 1 , 1 ));
1110
- local .add (createNode (new ImmutableCapabilities ("browserName" , "cheese" ), 1 , 0 ));
1146
+ CombinedHandler handler = new CombinedHandler ();
1147
+
1148
+ Node firstNode = createNode (new ImmutableCapabilities ("browserName" , "not cheese" ), 1 , 1 );
1149
+ Node secondNode = createNode (new ImmutableCapabilities ("browserName" , "cheese" ), 1 , 0 );
1150
+
1151
+ handler .addHandler (firstNode );
1152
+ handler .addHandler (secondNode );
1153
+
1154
+ local = new LocalDistributor (
1155
+ tracer ,
1156
+ bus ,
1157
+ new PassthroughHttpClient .Factory (handler ),
1158
+ sessions ,
1159
+ queue ,
1160
+ new DefaultSlotSelector (),
1161
+ registrationSecret ,
1162
+ Duration .ofMinutes (5 ),
1163
+ false );
1164
+
1165
+ local .add (firstNode );
1166
+ local .add (secondNode );
1111
1167
waitToHaveCapacity (local );
1112
1168
1113
1169
SessionRequest sessionRequest = new SessionRequest (
@@ -1132,8 +1188,23 @@ public void shouldFallbackToSecondAvailableCapabilitiesIfFirstNotAvailable() {
1132
1188
1133
1189
@ Test
1134
1190
public void shouldFallbackToSecondAvailableCapabilitiesIfFirstThrowsOnCreation () {
1135
- local .add (createBrokenNode (new ImmutableCapabilities ("browserName" , "not cheese" )));
1136
- local .add (createNode (new ImmutableCapabilities ("browserName" , "cheese" ), 1 , 0 ));
1191
+ CombinedHandler handler = new CombinedHandler ();
1192
+ Node brokenNode = createBrokenNode (new ImmutableCapabilities ("browserName" , "not cheese" ));
1193
+ Node node = createNode (new ImmutableCapabilities ("browserName" , "cheese" ), 1 , 0 );
1194
+ handler .addHandler (brokenNode );
1195
+ handler .addHandler (node );
1196
+ local = new LocalDistributor (
1197
+ tracer ,
1198
+ bus ,
1199
+ new PassthroughHttpClient .Factory (handler ),
1200
+ sessions ,
1201
+ queue ,
1202
+ new DefaultSlotSelector (),
1203
+ registrationSecret ,
1204
+ Duration .ofMinutes (5 ),
1205
+ false );
1206
+ local .add (brokenNode );
1207
+ local .add (node );
1137
1208
waitForAllNodesToHaveCapacity (local , 2 );
1138
1209
1139
1210
SessionRequest sessionRequest = new SessionRequest (
@@ -1188,7 +1259,7 @@ private void waitForAllNodesToHaveCapacity(Distributor distributor, int nodeCoun
1188
1259
private void waitForAllNodesToMeetCondition (Distributor distributor , int nodeCount ,
1189
1260
Availability availability ) {
1190
1261
new FluentWait <>(distributor )
1191
- .withTimeout (Duration .ofSeconds (5 ))
1262
+ .withTimeout (Duration .ofSeconds (10 ))
1192
1263
.pollingEvery (Duration .ofMillis (100 ))
1193
1264
.until (d -> {
1194
1265
Set <NodeStatus > nodes = d .getStatus ().getNodes ();
0 commit comments