Skip to content

Commit 2102284

Browse files
committed
Fix failing unit and integration tests
Requesting a client on an ElasticsearchNode in integration mode when the node hasn't started yet now throws an exception. This prevents false positives against already running node on 9200 (since we default to that port if not already started). Fixed 2 small unit test failures on PutRole's Names json output CatSnapshots did a snapshot of all indices, depending on when xunit decides to run this this could be a very very costly operation. We always limit to a single index now. Make sure we forcereseed as default on EnvironmentConfiguration RoleDetection integration tests still passed extra node settings using -D hardcoded which caused these integration tests to fail Conflicts: src/Nest/Nest.csproj src/Tests/ClientConcepts/ConnectionPooling/Sniffing/RoleDetection.doc.cs src/Tests/Framework/Integration/Process/ElasticsearchNode.cs src/Tests/Tests.csproj
1 parent fe89529 commit 2102284

File tree

8 files changed

+26
-15
lines changed

8 files changed

+26
-15
lines changed

paket.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
NUGET
2-
remote: http://api.nuget.org/v3/index.json
3-
specs:
4-
AsciiDocNet (1.0.0-alpha2)
5-
ShellProgressBar (3.0)
62
remote: https://www.nuget.org/api/v2
73
specs:
4+
AsciiDocNet (1.0.0-alpha3)
85
Bogus (3.0.5-beta-2)
96
Newtonsoft.Json (>= 8.0.2) - framework: >= net40, dnx451, dnxcore50
107
System.ComponentModel (>= 4.0.1-beta-23516) - framework: dnxcore50
@@ -351,6 +348,9 @@ NUGET
351348
System.Threading.Tasks (>= 4.0) - framework: dnxcore50
352349
xunit.abstractions (>= 2.0) - framework: dnxcore50
353350
xunit.extensibility.core (2.1) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0, wpav8.1
351+
remote: http://api.nuget.org/v3/index.json
352+
specs:
353+
ShellProgressBar (3.0)
354354

355355
GROUP build
356356
NUGET

src/Nest/Nest.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,6 @@
12411241
<ItemGroup>
12421242
<None Include="paket.references" />
12431243
</ItemGroup>
1244-
<ItemGroup />
12451244
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
12461245
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
12471246
Other similar extension points exist, see Microsoft.Common.targets.

src/Tests/Cat/CatSnapshots/CatSnapshotsApiTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
3434
throw new Exception("Setup: failed to create snapshot repository");
3535

3636
var createIndex = this.Client.CreateIndex(SnapshotIndexName);
37-
client.Snapshot(RepositoryName, SnapshotName, s=>s.WaitForCompletion());
37+
this.Client.ClusterHealth(g => g.WaitForStatus(WaitForStatus.Yellow));
38+
client.Snapshot(RepositoryName, SnapshotName, s=>s.WaitForCompletion().Index(SnapshotIndexName));
3839
}
3940

4041
protected override LazyResponses ClientUsage() => Calls(

src/Tests/Framework/Configuration/EnvironmentConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Tests.Framework.Configuration
99
public class EnvironmentConfiguration : TestConfigurationBase
1010
{
1111
public override bool DoNotSpawnIfAlreadyRunning { get; protected set; } = false;
12-
public override bool ForceReseed { get; protected set; } = false;
12+
public override bool ForceReseed { get; protected set; } = true;
1313
public override string ElasticsearchVersion { get; protected set; }
1414
public override TestMode Mode { get; protected set; } = TestMode.Unit;
1515

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ private ConnectionSettings ClusterSettings(ConnectionSettings s, Func<Connection
151151

152152
public IElasticClient Client(Func<Uri, IConnectionPool> createPool, Func<ConnectionSettings, ConnectionSettings> settings)
153153
{
154+
if (!this.Started && TestClient.Configuration.RunIntegrationTests)
155+
throw new Exception("can not request a client from an ElasticsearchNode if that node hasn't started yet");
154156
var port = this.Started ? this.Port : 9200;
155157
settings = settings ?? (s => s);
156158
var client = TestClient.GetClient(s => ClusterSettings(s, settings), port, createPool);
@@ -159,7 +161,14 @@ public IElasticClient Client(Func<Uri, IConnectionPool> createPool, Func<Connect
159161

160162
public IElasticClient Client(Func<ConnectionSettings, ConnectionSettings> settings = null, bool forceInMemory = false)
161163
{
164+
if (!this.Started && TestClient.Configuration.RunIntegrationTests)
165+
throw new Exception("can not request a client from an ElasticsearchNode if that node hasn't started yet");
162166
var port = this.Started ? this.Port : 9200;
167+
return GetPrivateClient(settings, forceInMemory, port);
168+
}
169+
170+
private IElasticClient GetPrivateClient(Func<ConnectionSettings, ConnectionSettings> settings, bool forceInMemory, int port)
171+
{
163172
settings = settings ?? (s => s);
164173
var client = forceInMemory
165174
? TestClient.GetInMemoryClient(s => ClusterSettings(s, settings), port)
@@ -287,11 +296,12 @@ private void HandleConsoleMessage(ElasticsearchMessage s, ManualResetEvent handl
287296
}
288297
else if (s.TryGetStartedConfirmation())
289298
{
290-
var healthyCluster = this.Client().ClusterHealth(g => g.WaitForStatus(WaitForStatus.Yellow).Timeout(TimeSpan.FromSeconds(30)));
299+
var healthyCluster = this.GetPrivateClient(null, false, this.Port)
300+
.ClusterHealth(g => g.WaitForStatus(WaitForStatus.Yellow).Timeout(TimeSpan.FromSeconds(30)));
291301
if (healthyCluster.IsValid)
292302
{
293-
this._blockingSubject.OnNext(handle);
294303
this.Started = true;
304+
this._blockingSubject.OnNext(handle);
295305
}
296306
else
297307
{
@@ -450,12 +460,11 @@ private ConnectionSettings AppendClusterNameToHttpHeaders(ConnectionSettings set
450460

451461
public void Stop()
452462
{
453-
if (!this.RunningIntegrations || !this.Started) return;
454463

464+
var hasStarted = this.Started;
455465
this.Started = false;
456466

457-
Console.WriteLine($"Stopping... ran integrations: {this.RunningIntegrations}");
458-
Console.WriteLine($"Node started: {this.Started} on port: {this.Port} using PID: {this.Info?.Pid}");
467+
Console.WriteLine($"Stopping... node has started {hasStarted} ran integrations: {this.RunningIntegrations}");
459468

460469
this._process?.Dispose();
461470
this._processListener?.Dispose();
@@ -469,6 +478,9 @@ public void Stop()
469478
esProcess.Close();
470479
}
471480

481+
if (!this.RunningIntegrations || !hasStarted) return;
482+
Console.WriteLine($"Node started on port: {this.Port} using PID: {this.Info?.Pid}");
483+
472484
if (this._doNotSpawnIfAlreadyRunning) return;
473485
var dataFolder = Path.Combine(this.RoamingClusterFolder, "data", this.ClusterName);
474486
if (Directory.Exists(dataFolder))

src/Tests/Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@
602602
<Content Include="ClientConcepts\LowLevel\pipeline.xml" />
603603
<Content Include="QueryDsl\BoolDsl\hadouken-indentation.jpg" />
604604
</ItemGroup>
605-
<ItemGroup />
606605
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
607606
<Choose>
608607
<When Condition="$(TargetFrameworkIdentifier) == '.NETCore' And $(TargetFrameworkVersion) == 'v4.5.1'">

src/Tests/XPack/Security/Role/PutRole/PutRoleApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override LazyResponses ClientUsage() => Calls(
4141
run_as = new [] { "user" },
4242
indices = new [] {
4343
new {
44-
names = "project",
44+
names = new [] { "project" },
4545
privileges = new [] { "all" },
4646
fields = new [] { "name", "description" },
4747
query = new { match_all = new {} }

src/Tests/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: m
2+
mode: i
33
# the elasticsearch version that should be started
44
elasticsearch_version: 5.0.0-alpha1
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running

0 commit comments

Comments
 (0)