Skip to content

Commit b82856d

Browse files
committed
Fix unit test, revert behavior as before
1 parent 9e61840 commit b82856d

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

java/src/org/openqa/selenium/grid/data/NodeStatus.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,17 @@ public static NodeStatus fromJson(JsonInput input) {
139139
}
140140

141141
public boolean hasCapability(Capabilities caps, SlotMatcher slotMatcher) {
142-
return this.getAvailability() == Availability.UP
143-
&& slots.stream().anyMatch(slot -> slot.isSupporting(caps, slotMatcher));
142+
return slots.stream().anyMatch(slot -> slot.isSupporting(caps, slotMatcher));
144143
}
145144

146145
public boolean hasCapacity() {
147-
return this.getAvailability() == Availability.UP
148-
&& slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount;
146+
return slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount;
149147
}
150148

151149
// Check if the Node's max session limit is not exceeded and has a free slot that supports the
152150
// capability.
153151
public boolean hasCapacity(Capabilities caps, SlotMatcher slotMatcher) {
154-
return this.getAvailability() == Availability.UP
155-
&& slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount
152+
return slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount
156153
&& slots.stream()
157154
.anyMatch(slot -> slot.getSession() == null && slot.isSupporting(caps, slotMatcher));
158155
}

java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ private SlotId reserveSlot(RequestId requestId, Capabilities caps) {
704704
}
705705

706706
private boolean isNotSupported(Capabilities caps) {
707-
return getAvailableNodes().stream().noneMatch(node -> node.hasCapability(caps, slotMatcher));
707+
return getAvailableNodes().stream()
708+
.noneMatch(node -> node.hasCapability(caps, slotMatcher) && node.getAvailability() == UP);
708709
}
709710

710711
private boolean reserve(SlotId id) {
@@ -794,7 +795,7 @@ public void run() {
794795
// up starving a session request.
795796
Map<Capabilities, Long> stereotypes =
796797
getAvailableNodes().stream()
797-
.filter(NodeStatus::hasCapacity)
798+
.filter(node -> node.hasCapacity() && node.getAvailability() == UP)
798799
.flatMap(node -> node.getSlots().stream().map(Slot::getStereotype))
799800
.collect(
800801
Collectors.groupingBy(ImmutableCapabilities::copyOf, Collectors.counting()));

java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.grid.distributor.selector;
1919

2020
import static com.google.common.collect.ImmutableSet.toImmutableSet;
21+
import static org.openqa.selenium.grid.data.Availability.UP;
2122

2223
import com.google.common.annotations.VisibleForTesting;
2324
import java.util.Comparator;
@@ -48,7 +49,7 @@ public Set<SlotId> selectSlot(
4849
// Nodes).
4950
// After that, Nodes are ordered by their load, last session creation, and their id.
5051
return nodes.stream()
51-
.filter(node -> node.hasCapacity(capabilities, slotMatcher))
52+
.filter(node -> node.hasCapacity(capabilities, slotMatcher) && node.getAvailability() == UP)
5253
.sorted(
5354
Comparator.comparingLong(this::getNumberOfSupportedBrowsers)
5455
// Now sort by node which has the lowest load (natural ordering)

0 commit comments

Comments
 (0)