Skip to content

Commit 7288c9b

Browse files
Fix integration tests (#4864) (#4865)
This commit makes some changes to integration tests that - are flaky on CI - send data that is not valid and is now validated - make assertions that may not hold with all test seeds Co-authored-by: Russ Cam <russ.cam@elastic.co>
1 parent 2e1e5ce commit 7288c9b

File tree

9 files changed

+39
-21
lines changed

9 files changed

+39
-21
lines changed

tests/Tests/Cluster/NodesStats/NodesStatsApiTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,7 @@ protected void Assert(ProcessStats process)
189189

190190
protected void Assert(ScriptStats script) => script.Should().NotBeNull();
191191

192-
protected void Assert(ScriptCacheStats scriptCache)
193-
{
194-
scriptCache.Should().NotBeNull();
195-
scriptCache.Sum.Should().NotBeNull();
196-
}
192+
protected void Assert(ScriptCacheStats scriptCache) => scriptCache?.Sum.Should().NotBeNull();
197193

198194
protected void Assert(TransportStats transport) => transport.Should().NotBeNull();
199195

tests/Tests/Document/Multiple/DeleteByQuery/DeleteByQueryApiTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
66
using System.Collections.Generic;
77
using System.Linq;
88
using Elasticsearch.Net;
@@ -211,7 +211,6 @@ protected override void ExpectResponse(DeleteByQueryResponse response)
211211
var failure = response.Failures.First();
212212

213213
failure.Index.Should().NotBeNullOrWhiteSpace();
214-
failure.Type.Should().NotBeNullOrWhiteSpace();
215214
failure.Status.Should().Be(409);
216215
failure.Id.Should().NotBeNullOrWhiteSpace();
217216

tests/Tests/Document/Multiple/UpdateByQuery/UpdateByQueryApiTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
5+
using System;
66
using System.Linq;
77
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
88
using Elasticsearch.Net;
@@ -194,7 +194,6 @@ protected override void ExpectResponse(UpdateByQueryResponse response)
194194
var failure = response.Failures.First();
195195

196196
failure.Index.Should().NotBeNullOrWhiteSpace();
197-
failure.Type.Should().NotBeNullOrWhiteSpace();
198197
failure.Status.Should().Be(409);
199198
failure.Id.Should().NotBeNullOrWhiteSpace();
200199

tests/Tests/Mapping/Types/Core/Binary/BinaryPropertyTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public BinaryPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(
2222
{
2323
type = "binary",
2424
doc_values = true,
25-
similarity = "BM25",
2625
store = true
2726
}
2827
}
@@ -32,7 +31,6 @@ public BinaryPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(
3231
.Binary(b => b
3332
.Name(p => p.Name)
3433
.DocValues()
35-
.Similarity("BM25")
3634
.Store()
3735
);
3836

@@ -42,7 +40,6 @@ public BinaryPropertyTests(WritableCluster cluster, EndpointUsage usage) : base(
4240
"name", new BinaryProperty
4341
{
4442
DocValues = true,
45-
Similarity = "BM25",
4643
Store = true
4744
}
4845
}

tests/Tests/Mapping/Types/Core/Boolean/BooleanPropertyTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public BooleanPropertyTests(WritableCluster cluster, EndpointUsage usage) : base
2323
type = "boolean",
2424
boost = 1.3,
2525
doc_values = false,
26-
similarity = "BM25",
2726
store = true,
2827
index = false,
2928
null_value = false,
@@ -36,7 +35,6 @@ public BooleanPropertyTests(WritableCluster cluster, EndpointUsage usage) : base
3635
.Name(p => p.Name)
3736
.Boost(1.3)
3837
.DocValues(false)
39-
.Similarity("BM25")
4038
.Store()
4139
.Index(false)
4240
.NullValue(false)
@@ -49,7 +47,6 @@ public BooleanPropertyTests(WritableCluster cluster, EndpointUsage usage) : base
4947
{
5048
DocValues = false,
5149
Boost = 1.3,
52-
Similarity = "BM25",
5350
Store = true,
5451
Index = false,
5552
NullValue = false

tests/Tests/XPack/MachineLearning/DeleteForecast/DeleteForecastApiTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
5252
}
5353
}
5454

55+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
56+
{
57+
foreach (var callUniqueValue in values)
58+
{
59+
CloseJob(client, callUniqueValue.Value + "-job");
60+
DeleteJob(client, callUniqueValue.Value + "-job");
61+
}
62+
}
63+
5564
protected override LazyResponses ClientUsage() => Calls(
5665
(client, f) => client.MachineLearning.DeleteForecast(CallIsolatedValue + "-job", CallIsolatedValue),
5766
(client, f) => client.MachineLearning.DeleteForecastAsync(CallIsolatedValue + "-job", CallIsolatedValue),

tests/Tests/XPack/MachineLearning/GetJobs/GetJobsApiTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
3030
foreach (var callUniqueValue in values) PutJob(client, callUniqueValue.Value);
3131
}
3232

33+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
34+
{
35+
foreach (var callUniqueValue in values) DeleteJob(client, callUniqueValue.Value);
36+
}
37+
3338
protected override LazyResponses ClientUsage() => Calls(
3439
(client, f) => client.MachineLearning.GetJobs(f),
3540
(client, f) => client.MachineLearning.GetJobsAsync(f),
@@ -90,6 +95,11 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
9095
foreach (var callUniqueValue in values) PutJob(client, callUniqueValue.Value);
9196
}
9297

98+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
99+
{
100+
foreach (var callUniqueValue in values) DeleteJob(client, callUniqueValue.Value);
101+
}
102+
93103
protected override LazyResponses ClientUsage() => Calls(
94104
(client, f) => client.MachineLearning.GetJobs(f),
95105
(client, f) => client.MachineLearning.GetJobsAsync(f),

tests/Tests/XPack/Security/User/InvalidateUserAccessToken/InvalidateUserAccessTokenApiTests.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Elasticsearch.Net;
88
using FluentAssertions;
99
using Nest;
10+
using Tests.Core.Client;
1011
using Tests.Core.Extensions;
1112
using Tests.Framework.EndpointTests;
1213
using Tests.Framework.EndpointTests.TestState;
@@ -69,8 +70,18 @@ public InvalidateUserAccessTokenBadPasswordApiTests(Security cluster, EndpointUs
6970
protected override string CurrentAccessToken => "bad_password";
7071

7172
protected override bool ExpectIsValid => false;
72-
protected override int ExpectStatusCode => 401;
73+
protected override int ExpectStatusCode => TestClient.Configuration.InRange("<7.8.0") ? 401 : 404;
7374

74-
protected override void ExpectResponse(InvalidateUserAccessTokenResponse response) => response.ServerError.Should().NotBeNull();
75+
protected override void ExpectResponse(InvalidateUserAccessTokenResponse response)
76+
{
77+
if (TestClient.Configuration.InRange("<7.8.0"))
78+
response.ServerError.Should().NotBeNull();
79+
else
80+
{
81+
response.InvalidatedTokens.Should().BeGreaterOrEqualTo(0);
82+
response.PreviouslyInvalidatedTokens.Should().BeGreaterOrEqualTo(0);
83+
response.ErrorCount.Should().BeGreaterOrEqualTo(0);
84+
}
85+
}
7586
}
7687
}

tests/Tests/XPack/Transform/TransformApiTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
233233
{
234234
StopTransformStep, u =>
235235
u.Calls<StopTransformDescriptor, StopTransformRequest, IStopTransformRequest, StopTransformResponse>(
236-
v => new StopTransformRequest(v) { Force = true, WaitForCompletion = true },
237-
(v, d) => d.Force().WaitForCompletion(),
236+
v => new StopTransformRequest(v) { Force = true, WaitForCompletion = true, Timeout = "2m"},
237+
(v, d) => d.Force().WaitForCompletion().Timeout("2m"),
238238
(v, c, f) => c.Transform.Stop(v, f),
239239
(v, c, f) => c.Transform.StopAsync(v, f),
240240
(v, c, r) => c.Transform.Stop(r),
@@ -244,8 +244,8 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne
244244
{
245245
DeleteTransformStep, u =>
246246
u.Calls<DeleteTransformDescriptor, DeleteTransformRequest, IDeleteTransformRequest, DeleteTransformResponse>(
247-
v => new DeleteTransformRequest(v),
248-
(v, d) => d,
247+
v => new DeleteTransformRequest(v) { Force = true },
248+
(v, d) => d.Force(),
249249
(v, c, f) => c.Transform.Delete(v, f),
250250
(v, c, f) => c.Transform.DeleteAsync(v, f),
251251
(v, c, r) => c.Transform.Delete(r),

0 commit comments

Comments
 (0)