Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grid] Consider max-session value while selecting the slot and identifying Node capacity #9838

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions java/src/org/openqa/selenium/grid/data/NodeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ public boolean hasCapacity() {
return slots.stream().anyMatch(slot -> slot.getSession() == null);
}

// Check if the Node's max session limit is not exceeded and has a free slot that supports the capability.
public boolean hasCapacity(Capabilities caps) {
return slots.stream()
.anyMatch(slot -> slot.getSession() == null && slot.isSupporting(caps));
return slots.stream().filter(slot -> slot.getSession() != null).count() < maxSessionCount &&
slots.stream().anyMatch(slot -> slot.getSession() == null && slot.isSupporting(caps));
}

public int getMaxSessionCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,37 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() {
assertThat(lightest.getSlots().stream()).anyMatch(slot -> expected.equals(slot.getId()));
}

@Test
public void theNodeWhichHasExceededMaxSessionsIsNotSelected() {
Capabilities chrome = new ImmutableCapabilities("browserName", "chrome");

NodeStatus lightLoad =
createNode(ImmutableList.of(chrome), 12, 2);
NodeStatus mediumLoad =
createNode(ImmutableList.of(chrome), 12, 5);
NodeStatus maximumLoad =
createNode(ImmutableList.of(chrome), 12, 12);

Set<SlotId> ids = selector.selectSlot(chrome, ImmutableSet.of(maximumLoad, mediumLoad, lightLoad));
SlotId expected = ids.iterator().next();

// The slot should belong to the Node with light load
assertThat(lightLoad.getSlots().stream())
.anyMatch(slot -> expected.equals(slot.getId()));

// The node whose current number of sessions is greater than or equal to the max sessions is not included
// Hence, the node with the maximum load is skipped
pujagani marked this conversation as resolved.
Show resolved Hide resolved
ImmutableSet<NodeId> nodeIds = ids.stream()
.map(SlotId::getOwningNodeId)
.distinct()
.collect(toImmutableSet());
assertThat(nodeIds).doesNotContain(maximumLoad.getNodeId());
assertThat(nodeIds)
.containsSequence(
lightLoad.getNodeId(),
mediumLoad.getNodeId());
}

@Test
public void nodesAreOrderedByNumberOfSupportedBrowsersAndLoad() {
Capabilities chrome = new ImmutableCapabilities("browserName", "chrome");
Expand Down Expand Up @@ -161,6 +192,7 @@ public void nodesAreOrderedByNumberOfSupportedBrowsersAndLoad() {
.anyMatch(slot -> expected.equals(slot.getId()));

// Nodes are ordered by the diversity of supported browsers, then by load
// The node whose current number of sessions is greater than or equal to the max sessions is not included
ImmutableSet<NodeId> nodeIds = ids.stream()
.map(SlotId::getOwningNodeId)
.distinct()
Expand All @@ -169,7 +201,6 @@ public void nodesAreOrderedByNumberOfSupportedBrowsersAndLoad() {
.containsSequence(
highLoadAndOneBrowser.getNodeId(),
mediumLoadAndTwoBrowsers.getNodeId(),
mediumLoadAndOtherTwoBrowsers.getNodeId(),
lightLoadAndThreeBrowsers.getNodeId());
}

Expand Down