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]: Capability se:vncEnabled value based on list of vnc-env-var #14584

Merged
merged 1 commit into from
Oct 10, 2024
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
9 changes: 6 additions & 3 deletions java/src/org/openqa/selenium/grid/node/config/NodeFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_REGISTER_PERIOD;
import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_SESSION_TIMEOUT;
import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_USE_SELENIUM_MANAGER;
import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_VNC_ENV_VAR;
import static org.openqa.selenium.grid.node.config.NodeOptions.DEFAULT_VNC_ENV_VARS;
import static org.openqa.selenium.grid.node.config.NodeOptions.NODE_SECTION;
import static org.openqa.selenium.grid.node.config.NodeOptions.OVERRIDE_MAX_SESSIONS;

Expand Down Expand Up @@ -202,8 +202,11 @@ public class NodeFlags implements HasRoles {
description =
"Environment variable to check in order to determine if a vnc stream is "
+ "available or not.")
@ConfigValue(section = NODE_SECTION, name = "vnc-env-var", example = "SE_START_XVFB")
public String vncEnvVar = DEFAULT_VNC_ENV_VAR;
@ConfigValue(
section = NODE_SECTION,
name = "vnc-env-var",
example = "[\"SE_START_XVFB\", \"SE_START_VNC\", \"SE_START_NO_VNC\"]")
public List<String> vncEnvVar = DEFAULT_VNC_ENV_VARS;

@Parameter(
names = "--no-vnc-port",
Expand Down
15 changes: 12 additions & 3 deletions java/src/org/openqa/selenium/grid/node/config/NodeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -78,7 +79,8 @@ public class NodeOptions {
static final boolean DEFAULT_DETECT_DRIVERS = true;
static final boolean DEFAULT_USE_SELENIUM_MANAGER = false;
static final boolean OVERRIDE_MAX_SESSIONS = false;
static final String DEFAULT_VNC_ENV_VAR = "SE_START_XVFB";
static final List<String> DEFAULT_VNC_ENV_VARS =
Arrays.asList("SE_START_XVFB", "SE_START_VNC", "SE_START_NO_VNC");
static final int DEFAULT_NO_VNC_PORT = 7900;
static final int DEFAULT_REGISTER_CYCLE = 10;
static final int DEFAULT_REGISTER_PERIOD = 120;
Expand Down Expand Up @@ -286,9 +288,16 @@ public int getDrainAfterSessionCount() {

@VisibleForTesting
boolean isVncEnabled() {
String vncEnvVar = config.get(NODE_SECTION, "vnc-env-var").orElse(DEFAULT_VNC_ENV_VAR);
List<String> vncEnvVars = DEFAULT_VNC_ENV_VARS;
if (config.getAll(NODE_SECTION, "vnc-env-var").isPresent()) {
vncEnvVars = config.getAll(NODE_SECTION, "vnc-env-var").get();
}
if (!vncEnabledValueSet.getAndSet(true)) {
vncEnabled.set(Boolean.parseBoolean(System.getenv(vncEnvVar)));
boolean allEnabled =
vncEnvVars.stream()
.allMatch(
env -> "true".equalsIgnoreCase(System.getProperty(env, System.getenv(env))));
vncEnabled.set(allEnabled);
}
return vncEnabled.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,50 @@ void settingSlotMatcherAvailable() {
assertThat(nodeOptions.getSlotMatcher()).isExactlyInstanceOf(YesSlotMatcher.class);
}

@Test
void testIsVncEnabledAcceptListEnvVarsAndReturnTrue() {
System.setProperty("SE_START_XVFB", "true");
System.setProperty("SE_START_VNC", "true");
System.setProperty("SE_START_NO_VNC", "true");
String[] rawConfig =
new String[] {
"[node]", "vnc-env-var = [\"SE_START_XVFB\", \"SE_START_VNC\", \"SE_START_NO_VNC\"]",
};
Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));
NodeOptions nodeOptionsEnabled = new NodeOptions(config);
assertThat(config.getAll("node", "vnc-env-var").get())
.containsExactly("SE_START_XVFB", "SE_START_VNC", "SE_START_NO_VNC");
assertThat(nodeOptionsEnabled.isVncEnabled()).isTrue();
}

@Test
void testIsVncEnabledAcceptListEnvVarsAndReturnFalse() {
System.setProperty("SE_START_XVFB", "true");
System.setProperty("SE_START_VNC", "false");
String[] rawConfig =
new String[] {
"[node]", "vnc-env-var = [\"SE_START_XVFB\", \"SE_START_VNC\", \"SE_START_NO_VNC\"]",
};
Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));
NodeOptions nodeOptionsEnabled = new NodeOptions(config);
assertThat(config.getAll("node", "vnc-env-var").get())
.containsExactly("SE_START_XVFB", "SE_START_VNC", "SE_START_NO_VNC");
assertThat(nodeOptionsEnabled.isVncEnabled()).isFalse();
}

@Test
void testIsVncEnabledAcceptSingleEnvVar() {
System.setProperty("SE_START_XVFB", "false");
String[] rawConfig =
new String[] {
"[node]", "vnc-env-var = \"SE_START_XVFB\"",
};
Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));
NodeOptions nodeOptionsEnabled = new NodeOptions(config);
assertThat(config.getAll("node", "vnc-env-var").get()).containsExactly("SE_START_XVFB");
assertThat(nodeOptionsEnabled.isVncEnabled()).isFalse();
}

private Condition<? super List<? extends Capabilities>> supporting(String name) {
return new Condition<>(
caps -> caps.stream().anyMatch(cap -> name.equals(cap.getBrowserName())),
Expand Down
Loading