From 3a08009aff2a2186a464dc739a97c3f951251af3 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 18 Feb 2021 12:36:50 +0100 Subject: [PATCH] Bump testing abstraction and fix cluster run command (#5330) --- build/scripts/Paths.fs | 2 ++ build/scripts/ReposTooling.fs | 2 +- build/scripts/scripts.fsproj | 2 +- nuget.config | 1 - .../ClusterLaunchProgram.cs | 19 +++++++++++++------ .../Tests.Configuration.csproj | 2 +- tests/Tests.Core/Tests.Core.csproj | 2 +- tests/Tests.Domain/Tests.Domain.csproj | 2 +- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/build/scripts/Paths.fs b/build/scripts/Paths.fs index 0f206d90d0f..2ae2badca4d 100644 --- a/build/scripts/Paths.fs +++ b/build/scripts/Paths.fs @@ -18,6 +18,8 @@ module Paths = let InplaceBuildOutput project tfm = sprintf "src/%s/bin/Release/%s" project tfm + let InplaceBuildTestOutput project tfm = + sprintf "tests/%s/bin/Release/%s" project tfm let MagicDocumentationFile = "src/Elasticsearch.Net/obj/Release/netstandard2.1/Elasticsearch.Net.csprojAssemblyReference.cache" diff --git a/build/scripts/ReposTooling.fs b/build/scripts/ReposTooling.fs index 928173f5af3..aa81f9182b9 100644 --- a/build/scripts/ReposTooling.fs +++ b/build/scripts/ReposTooling.fs @@ -15,7 +15,7 @@ module ReposTooling = let clusterName = Option.defaultValue "" <| match args.CommandArguments with | Cluster c -> Some c.Name | _ -> None let clusterVersion = Option.defaultValue "" <|match args.CommandArguments with | Cluster c -> c.Version | _ -> None - let testsProjectDirectory = Path.Combine(Path.GetFullPath(Paths.Output("Tests.ClusterLauncher")), "net5.0") + let testsProjectDirectory = Path.GetFullPath(Paths.InplaceBuildTestOutput "Tests.ClusterLauncher" "net5.0") let tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); printfn "%s" testsProjectDirectory diff --git a/build/scripts/scripts.fsproj b/build/scripts/scripts.fsproj index 30673ae171f..34218b5ca4a 100644 --- a/build/scripts/scripts.fsproj +++ b/build/scripts/scripts.fsproj @@ -38,7 +38,7 @@ - + diff --git a/nuget.config b/nuget.config index 6405b5ef144..8d468146819 100644 --- a/nuget.config +++ b/nuget.config @@ -1,7 +1,6 @@  - \ No newline at end of file diff --git a/tests/Tests.ClusterLauncher/ClusterLaunchProgram.cs b/tests/Tests.ClusterLauncher/ClusterLaunchProgram.cs index d2d4e261767..0d0b5f2d587 100644 --- a/tests/Tests.ClusterLauncher/ClusterLaunchProgram.cs +++ b/tests/Tests.ClusterLauncher/ClusterLaunchProgram.cs @@ -38,8 +38,8 @@ public static int Main(string[] arguments) if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NEST_YAML_FILE"))) { // build always sets previous argument, assume we are running from the IDE or dotnet run - var yamlFile = TestConfiguration.LocateTestYamlFile(); - Environment.SetEnvironmentVariable("NEST_YAML_FILE", yamlFile, EnvironmentVariableTarget.Process); + var yamlFile = TestConfiguration.LocateTestYamlFile(); + Environment.SetEnvironmentVariable("NEST_YAML_FILE", yamlFile, EnvironmentVariableTarget.Process); } // if version is passed this will take precedence over the version in the yaml file @@ -61,12 +61,19 @@ public static int Main(string[] arguments) AppDomain.CurrentDomain.ProcessExit += (s, ev) => Instance?.Dispose(); Console.CancelKeyPress += (s, ev) => Instance?.Dispose(); - if (!TryStartClientTestClusterBaseImplementation(cluster) && !TryStartXPackClusterImplementation(cluster)) + try { + if (TryStartClientTestClusterBaseImplementation(cluster) || TryStartXPackClusterImplementation(cluster)) return 0; + Console.Error.WriteLine($"Could not create an instance of '{cluster.FullName}"); return 1; } - return 0; + catch (Exception e) + { + Console.WriteLine(e); + Instance?.Dispose(); + throw; + } } private static bool TryStartXPackClusterImplementation(Type cluster) @@ -91,7 +98,7 @@ private static bool TryStartClientTestClusterBaseImplementation(Type cluster) private static bool Run(ICluster instance) { TestConfiguration.Instance.DumpConfiguration(); - instance.Start(); + using var start = instance.Start(); if (!instance.Started) { Console.Error.WriteLine($"Failed to start cluster: '{instance.GetType().FullName}"); @@ -118,7 +125,7 @@ private static Type[] GetClusters() return types .Where(t => t.Implements(typeof(IEphemeralCluster))) - .Where(t=> !t.IsAbstract) + .Where(t => !t.IsAbstract) .ToArray(); } } diff --git a/tests/Tests.Configuration/Tests.Configuration.csproj b/tests/Tests.Configuration/Tests.Configuration.csproj index 56a5b775972..8dc3dc5bd88 100644 --- a/tests/Tests.Configuration/Tests.Configuration.csproj +++ b/tests/Tests.Configuration/Tests.Configuration.csproj @@ -3,6 +3,6 @@ netstandard2.0 - + \ No newline at end of file diff --git a/tests/Tests.Core/Tests.Core.csproj b/tests/Tests.Core/Tests.Core.csproj index ea0d8f66438..355e97eb938 100644 --- a/tests/Tests.Core/Tests.Core.csproj +++ b/tests/Tests.Core/Tests.Core.csproj @@ -16,7 +16,7 @@ - + diff --git a/tests/Tests.Domain/Tests.Domain.csproj b/tests/Tests.Domain/Tests.Domain.csproj index 846b8d2a702..9091cc6ede0 100644 --- a/tests/Tests.Domain/Tests.Domain.csproj +++ b/tests/Tests.Domain/Tests.Domain.csproj @@ -11,7 +11,7 @@ - +