Skip to content

Commit db92f95

Browse files
committed
Integrations test suite improvements
JAVA_HOME is not necessary for the bat files anymore but the shield bat files do not have the same JAVA_HOME path guessing so they bork. Causing a rather nasty AppDomainUnloaded exception which obfuscates the true cause. Similarly a bad x-pack license behaved the exact same. Improved error reporting to adduser in the bootstrap for the xpack cluster. Also added SkipVersions for integration tests against 5.0 and <5.1
1 parent de5d2a4 commit db92f95

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

build.bat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SET ESVERSIONS=
2424
SET SKIPTESTS=0
2525
SET APIKEY=
2626
SET APIKEYPROVIDED="<empty>"
27-
SET FEED="elasticsearch-net"
27+
SET FEED="elasticsearch-net"
2828
SET NEST_INTEGRATION_CLUSTER=
2929
SET NEST_TEST_FILTER=
3030

@@ -44,12 +44,20 @@ IF /I "%1"=="release" (
4444
IF NOT [%2]==[] (set VERSION="%2")
4545
IF /I "%3"=="skiptests" (set SKIPTESTS=1)
4646
IF /I "%2"=="skiptests" (set SKIPTESTS=1)
47+
IF /I "%JAVA_HOME%"=="" (
48+
ECHO JAVA_HOME not set exiting release early!
49+
EXIT /B 1
50+
)
4751
)
4852

4953
IF /I "%1%"=="integrate" (
5054
IF NOT [%2]==[] (set ESVERSIONS="%2")
5155
IF NOT [%3]==[] (set NEST_INTEGRATION_CLUSTER="%3")
5256
IF NOT [%4]==[] (set NEST_TEST_FILTER="%4")
57+
IF /I "%JAVA_HOME%"=="" (
58+
ECHO JAVA_HOME not set exiting integration tests early!
59+
EXIT /B 1
60+
)
5361
)
5462

5563
IF /I "%1%"=="canary" (

src/Tests/Cat/CatTemplates/CatTemplatesApiTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Tests.Cat.CatTemplates
99
{
10+
[SkipVersion("<5.1.0", "CatTemplates is an API introduced in 5.1")]
1011
public class CatTemplatesApiTests : ApiIntegrationTestBase<ReadOnlyCluster, ICatResponse<CatTemplatesRecord>, ICatTemplatesRequest, CatTemplatesDescriptor, CatTemplatesRequest>
1112
{
1213
public CatTemplatesApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

src/Tests/Framework/ManagedElasticsearch/FileSystem/TestRunnerFileSystem.cs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private void DownloadAndExtractElasticsearch()
6363
if (!Directory.Exists(this.RoamingFolder))
6464
Directory.CreateDirectory(this.RoamingFolder);
6565

66+
EnsureJavaHome();
6667
DownloadDistributionZip();
6768
UnzipDistribution();
6869
CreateHelperBatFile();
@@ -239,29 +240,57 @@ private void EnsureWatcherActionConfigurations()
239240
if (saveFile) File.WriteAllLines(rolesConfig, lines);
240241
}
241242

243+
private void EnsureJavaHome()
244+
{
245+
#if DOTNETCORE
246+
var javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
247+
#else
248+
var javaHome = Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.Machine)
249+
?? Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.User);
250+
#endif
251+
if (string.IsNullOrWhiteSpace(javaHome))
252+
throw new Exception("The elasticsearch bat files are resillient to JAVA_HOME not being set, however the shield tooling is not");
253+
}
254+
242255
private void EnsureShieldAdmin()
243256
{
244257
if (!this._config.XPackEnabled) return;
245258

259+
246260
var folder = this.Version.Major >= 5 ? "x-pack" : "shield";
247261
var plugin = this.Version.Major >= 5 ? "users" : "esusers";
248262

249263
EnsureRoles(folder);
264+
var timeout = TimeSpan.FromMinutes(1);
265+
250266
var pluginBat = Path.Combine(this.ElasticsearchHome, "bin", folder, plugin) + ".bat";
251267
foreach (var cred in ShieldInformation.AllUsers)
252268
{
253-
var processInfo = new ProcessStartInfo
269+
var handle = new ManualResetEvent(false);
270+
Task.Run(() =>
254271
{
255-
FileName = pluginBat,
256-
Arguments = $"useradd {cred.Username} -p {cred.Password} -r {cred.Role}",
257-
CreateNoWindow = true,
258-
UseShellExecute = false,
259-
RedirectStandardOutput = false,
260-
RedirectStandardError = false,
261-
RedirectStandardInput = false
262-
};
263-
var p = Process.Start(processInfo);
264-
p.WaitForExit();
272+
using (var p = new ObservableProcess(pluginBat, $"useradd {cred.Username} -p {cred.Password} -r {cred.Role}"))
273+
{
274+
var o = p.Start();
275+
Console.WriteLine($"Calling: {pluginBat} useradd {cred.Username}");
276+
o.Subscribe(
277+
//c=>Console.WriteLine(c.Data),
278+
c => { },
279+
(e) =>
280+
{
281+
handle.Set();
282+
throw e;
283+
},
284+
() =>
285+
{
286+
handle.Set();
287+
});
288+
if (!handle.WaitOne(timeout, true))
289+
throw new Exception($"Could not add user {cred.Username} within {timeout}");
290+
}
291+
});
292+
if (!handle.WaitOne(timeout, true))
293+
throw new Exception($"Could not add user {cred.Username} within {timeout}");
265294
}
266295
}
267296

src/Tests/Framework/ManagedElasticsearch/Process/ElasticsearchNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public IObservable<ElasticsearchConsoleOut> Start(string[] additionalSettings =
131131
private Exception Exception { get; set; }
132132
private void Fatal(XplatManualResetEvent handle, Exception exception = null)
133133
{
134+
Console.WriteLine("FATAL called: " + exception?.Message);
135+
134136
if (exception != null) this.Exception = exception;
135137
handle?.Set();
136138
this.Stop();

src/Tests/Framework/Xunit/TestAssemblyRunner.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ orderby g.Count() descending
7373
var type = group.Key?.GetType();
7474
var clusterName = type?.Name.Replace("Cluster", "") ?? "UNKNOWN";
7575

76-
if (!string.IsNullOrWhiteSpace(clusterFilter) &&
77-
!string.Equals(clusterName, clusterFilter, StringComparison.OrdinalIgnoreCase))
76+
if (!string.IsNullOrWhiteSpace(clusterFilter) && clusterName.IndexOf(clusterFilter, StringComparison.OrdinalIgnoreCase) < 0)
7877
continue;
7978

8079
var dop = group.Key != null && group.Key.MaxConcurrency > 0
@@ -91,8 +90,7 @@ orderby g.Count() descending
9190
await group.ForEachAsync(dop, async g =>
9291
{
9392
var test = g.Collection.DisplayName.Replace("Test collection for", "");
94-
if (!string.IsNullOrWhiteSpace(testFilter) &&
95-
test.IndexOf(testFilter, StringComparison.OrdinalIgnoreCase) < 0)
93+
if (!string.IsNullOrWhiteSpace(testFilter) && test.IndexOf(testFilter, StringComparison.OrdinalIgnoreCase) < 0)
9694
return;
9795

9896
//display tests we execute when we filter so we get confirmation on the command line we run the tests we expect

src/Tests/Indices/StatusManagement/Upgrade/UpgradeApiTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Tests.Indices.StatusManagement.Upgrade
1111
{
12+
[SkipVersion("<=5.0.0", "AllowNoIndices() only available from 5.0.1 onwards")]
1213
public class UpgradeApiTests
1314
: ApiIntegrationAgainstNewIndexTestBase
1415
<IntrusiveOperationCluster, IUpgradeResponse, IUpgradeRequest, UpgradeDescriptor, UpgradeRequest>

0 commit comments

Comments
 (0)