Skip to content

Commit d6cb6cb

Browse files
committed
Use bazel run
1 parent 009cbfe commit d6cb6cb

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

dotnet/test/common/Environment/TestWebServer.cs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using System.IO;
2424
using System.Net;
2525
using System.Net.Http;
26-
using System.Runtime.InteropServices;
2726
using System.Text;
2827
using System.Threading.Tasks;
2928

@@ -33,21 +32,17 @@ public class TestWebServer
3332
{
3433
private Process webserverProcess;
3534

36-
private string standaloneAppserverPath = @"_main/java/test/org/openqa/selenium/environment/appserver";
35+
private string standaloneAppserverPath;
3736
private string projectRootPath;
3837
private bool captureWebServerOutput;
3938
private bool hideCommandPrompt;
40-
private string javaHomeDirectory;
4139
private string port;
4240

43-
private StringBuilder outputData = new StringBuilder();
44-
4541
public TestWebServer(string projectRoot, TestWebServerConfig config)
4642
{
4743
this.projectRootPath = projectRoot;
4844
this.captureWebServerOutput = config.CaptureConsoleOutput;
4945
this.hideCommandPrompt = config.HideCommandPromptWindow;
50-
this.javaHomeDirectory = config.JavaHomeDirectory;
5146
this.port = config.Port;
5247
}
5348

@@ -58,41 +53,30 @@ public async Task StartAsync()
5853
try
5954
{
6055
var runfiles = Runfiles.Create();
61-
standaloneAppserverPath = runfiles.Rlocation(standaloneAppserverPath);
56+
standaloneAppserverPath = runfiles.Rlocation(@"_main/java/test/org/openqa/selenium/environment/appserver");
6257
}
58+
// means we are NOT running under bazel runtime
59+
// most likely in IDE
6360
catch (FileNotFoundException)
6461
{
65-
var baseDirectory = AppContext.BaseDirectory;
66-
standaloneAppserverPath = Path.Combine(baseDirectory, "../../../../../../bazel-bin/java/test/org/openqa/selenium/environment/appserver");
62+
//var baseDirectory = AppContext.BaseDirectory;
63+
//standaloneAppserverPath = Path.Combine(baseDirectory, "../../../../../../bazel-bin/java/test/org/openqa/selenium/environment/appserver");
6764
}
6865

69-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
70-
{
71-
standaloneAppserverPath += ".exe";
72-
}
66+
var processFileName = standaloneAppserverPath ?? "bazel";
7367

74-
Console.Write("Test Appserver is " + standaloneAppserverPath);
68+
string processArguments = $"{port}";
7569

76-
if (!File.Exists(standaloneAppserverPath))
70+
if (standaloneAppserverPath is null)
7771
{
78-
throw new FileNotFoundException(
79-
string.Format(
80-
"Test Appserver at {0} didn't exist. Project root is {2}. Please build it using something like {1}.",
81-
standaloneAppserverPath,
82-
"bazel build //java/test/org/openqa/selenium/environment:appserver",
83-
projectRootPath));
72+
processArguments = $"run //java/test/org/openqa/selenium/environment:appserver {processArguments}";
73+
projectRootPath = Path.Combine(AppContext.BaseDirectory, "../../../../../..");
8474
}
8575

86-
StringBuilder processArgsBuilder = new StringBuilder();
87-
88-
processArgsBuilder.AppendFormat(" {0}", this.port);
89-
90-
Console.Write(processArgsBuilder.ToString());
91-
9276
webserverProcess = new Process();
93-
webserverProcess.StartInfo.FileName = standaloneAppserverPath;
9477

95-
webserverProcess.StartInfo.Arguments = processArgsBuilder.ToString();
78+
webserverProcess.StartInfo.FileName = processFileName;
79+
webserverProcess.StartInfo.Arguments = processArguments;
9680
webserverProcess.StartInfo.WorkingDirectory = projectRootPath;
9781
webserverProcess.StartInfo.UseShellExecute = !(hideCommandPrompt || captureWebServerOutput);
9882
webserverProcess.StartInfo.CreateNoWindow = hideCommandPrompt;
@@ -140,7 +124,8 @@ public async Task StartAsync()
140124
output = webserverProcess.StandardOutput.ReadToEnd();
141125
}
142126

143-
string errorMessage = string.Format("Could not start the test web server in {0} seconds.\nWorking directory: {1}\nProcess Args: {2}\nstdout: {3}\nstderr: {4}", timeout.TotalSeconds, projectRootPath, processArgsBuilder, output, error);
127+
string errorMessage = string.Format("Could not start the test web server in {0} seconds.\nWorking directory: {1}\nProcess Args: {2}\nstdout: {3}\nstderr: {4}", timeout.TotalSeconds, projectRootPath, processArguments, output, error);
128+
144129
throw new TimeoutException(errorMessage);
145130
}
146131
}

0 commit comments

Comments
 (0)