Skip to content

Commit

Permalink
Updating finding of test web server for .NET tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jul 1, 2019
1 parent 005a942 commit 283a2b8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
57 changes: 51 additions & 6 deletions dotnet/test/common/Environment/EnvironmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using Newtonsoft.Json;
using NUnit.Framework;
using System.Collections.Generic;

namespace OpenQA.Selenium.Environment
{
Expand All @@ -21,8 +22,9 @@ public class EnvironmentManager
private EnvironmentManager()
{
string currentDirectory = this.CurrentDirectory;
string configFile = Path.Combine(currentDirectory, "appconfig.json");

string defaultConfigFile = Path.Combine(currentDirectory, "appconfig.json");
string configFile = TestContext.Parameters.Get<string>("ConfigFile", defaultConfigFile).Replace('/', Path.DirectorySeparatorChar);

string content = File.ReadAllText(configFile);
TestEnvironment env = JsonConvert.DeserializeObject<TestEnvironment>(content);

Expand All @@ -48,14 +50,57 @@ private EnvironmentManager()
string projectRoot = System.Environment.GetEnvironmentVariable("TEST_SRCDIR");
if (string.IsNullOrEmpty(projectRoot))
{
// Walk up the directory tree until we find ourselves in a directory
// where the path to the Java web server can be determined.
bool continueTraversal = true;
DirectoryInfo info = new DirectoryInfo(currentDirectory);
while (info != info.Root && string.Compare(info.Name, "bazel-out", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(info.Name, "buck-out", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(info.Name, "build", StringComparison.OrdinalIgnoreCase) != 0)
while (continueTraversal)
{
info = info.Parent;
if (info == info.Root)
{
break;
}

foreach (var childDir in info.EnumerateDirectories())
{
// Case 1: The current directory of this assembly is in the
// same direct sub-tree as the Java targets (usually meaning
// executing tests from the same build system as that which
// builds the Java targets).
// If we find a child directory named "java", then the web
// server should be able to be found under there.
if (string.Compare(childDir.Name, "java", StringComparison.OrdinalIgnoreCase) == 0)
{
continueTraversal = false;
break;
}

// Case 2: The current directory of this assembly is a different
// sub-tree as the Java targets (usually meaning executing tests
// from a different build system as that which builds the Java
// targets).
// If we travel to a place in the tree where there is a child
// directory named "bazel-bin", the web server should be found
// in the "java" subdirectory of that directory.
if (string.Compare(childDir.Name, "bazel-bin", StringComparison.OrdinalIgnoreCase) == 0)
{
string javaOutDirectory = Path.Combine(childDir.FullName, "java");
if (Directory.Exists(javaOutDirectory))
{
info = new DirectoryInfo(javaOutDirectory);
continueTraversal = false;
break;
}
}
}

if (continueTraversal)
{
info = info.Parent;
}
}

info = info.Parent;
projectRoot = Path.Combine(info.FullName, "bazel-bin");
projectRoot = info.FullName;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet/test/common/Environment/TestWebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void Start()
string error = "'CaptureWebServerOutput' parameter is false. Web server output not being captured.";
if (captureWebServerOutput)
{
webserverProcess.StandardError.ReadToEnd();
webserverProcess.StandardOutput.ReadToEnd();
error = webserverProcess.StandardError.ReadToEnd();
output = webserverProcess.StandardOutput.ReadToEnd();
}

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);
Expand Down

0 comments on commit 283a2b8

Please sign in to comment.