Skip to content

Commit f04ae60

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
1 parent 458e9d1 commit f04ae60

File tree

9 files changed

+31
-20
lines changed

9 files changed

+31
-20
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
@@ -1269,7 +1269,6 @@
12691269
<ItemGroup>
12701270
<None Include="paket.references" />
12711271
</ItemGroup>
1272-
<ItemGroup />
12731272
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
12741273
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
12751274
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/ClientConcepts/ConnectionPooling/Sniffing/RoleDetection.doc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public class SniffRoleDetectionCluster : ClusterBase, ICollectionFixture<SniffRo
114114
{
115115
protected override string[] ServerSettings => new[]
116116
{
117-
"-Des.node.data=false",
118-
"-Des.node.master=true",
117+
"es.node.data=false",
118+
"es.node.master=true",
119119
};
120120
}
121121

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: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ private ConnectionSettings ClusterSettings(ConnectionSettings s, Func<Connection
152152

153153
public IElasticClient Client(Func<Uri, IConnectionPool> createPool, Func<ConnectionSettings, ConnectionSettings> settings)
154154
{
155+
if (!this.Started && TestClient.Configuration.RunIntegrationTests)
156+
throw new Exception("can not request a client from an ElasticsearchNode if that node hasn't started yet");
155157
var port = this.Started ? this.Port : 9200;
156158
settings = settings ?? (s => s);
157159
var client = TestClient.GetClient(s => ClusterSettings(s, settings), port, createPool);
@@ -160,13 +162,20 @@ public IElasticClient Client(Func<Uri, IConnectionPool> createPool, Func<Connect
160162

161163
public IElasticClient Client(Func<ConnectionSettings, ConnectionSettings> settings = null, bool forceInMemory = false)
162164
{
165+
if (!this.Started && TestClient.Configuration.RunIntegrationTests)
166+
throw new Exception("can not request a client from an ElasticsearchNode if that node hasn't started yet");
163167
var port = this.Started ? this.Port : 9200;
168+
return GetPrivateClient(settings, forceInMemory, port);
169+
}
170+
171+
private IElasticClient GetPrivateClient(Func<ConnectionSettings, ConnectionSettings> settings, bool forceInMemory, int port)
172+
{
164173
settings = settings ?? (s => s);
165174
var client = forceInMemory
166175
? TestClient.GetInMemoryClient(s => ClusterSettings(s, settings), port)
167176
: TestClient.GetClient(s => ClusterSettings(s, settings), port);
168177
return client;
169-
}
178+
}
170179

171180
public IObservable<ElasticsearchMessage> Start(string typeOfCluster, string[] additionalSettings = null)
172181
{
@@ -288,11 +297,12 @@ private void HandleConsoleMessage(ElasticsearchMessage s, ManualResetEvent handl
288297
}
289298
else if (s.TryGetStartedConfirmation())
290299
{
291-
var healthyCluster = this.Client().ClusterHealth(g => g.WaitForStatus(WaitForStatus.Yellow).Timeout(TimeSpan.FromSeconds(30)));
300+
var healthyCluster = this.GetPrivateClient(null, false, this.Port)
301+
.ClusterHealth(g => g.WaitForStatus(WaitForStatus.Yellow).Timeout(TimeSpan.FromSeconds(30)));
292302
if (healthyCluster.IsValid)
293303
{
294-
this._blockingSubject.OnNext(handle);
295304
this.Started = true;
305+
this._blockingSubject.OnNext(handle);
296306
}
297307
else
298308
{
@@ -451,12 +461,11 @@ private ConnectionSettings AppendClusterNameToHttpHeaders(ConnectionSettings set
451461

452462
public void Stop()
453463
{
454-
if (!this.RunningIntegrations || !this.Started) return;
455464

465+
var hasStarted = this.Started;
456466
this.Started = false;
457467

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

461470
this._process?.Dispose();
462471
this._processListener?.Dispose();
@@ -468,7 +477,10 @@ public void Stop()
468477
esProcess.Kill();
469478
esProcess.WaitForExit(5000);
470479
esProcess.Close();
471-
}
480+
}
481+
482+
if (!this.RunningIntegrations || !hasStarted) return;
483+
Console.WriteLine($"Node started on port: {this.Port} using PID: {this.Info?.Pid}");
472484

473485
if (this._doNotSpawnIfAlreadyRunning) return;
474486
var dataFolder = Path.Combine(this.RoamingClusterFolder, "data", this.ClusterName);

src/Tests/Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@
630630
<Content Include="ClientConcepts\LowLevel\pipeline.xml" />
631631
<Content Include="QueryDsl\BoolDsl\hadouken-indentation.jpg" />
632632
</ItemGroup>
633-
<ItemGroup />
634633
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
635634
<Choose>
636635
<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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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: 2.3.0
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running
6-
force_reseed: false
6+
force_reseed: true
77
# do not spawn nodes as part of the test setup but rely on a manually started es node being up
88
do_not_spawn: true

0 commit comments

Comments
 (0)