From 6f5375431d8b81867c0412407d0b5cdb792e6452 Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Wed, 22 Jul 2020 13:24:53 +1000 Subject: [PATCH] Fix integration tests (#4864) 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 --- .../Cluster/NodesStats/NodesStatsApiTests.cs | 6 +----- .../DeleteByQuery/DeleteByQueryApiTests.cs | 3 +-- .../UpdateByQuery/UpdateByQueryApiTests.cs | 3 +-- .../Types/Core/Binary/BinaryPropertyTests.cs | 3 --- .../Types/Core/Boolean/BooleanPropertyTests.cs | 3 --- .../DeleteForecast/DeleteForecastApiTests.cs | 9 +++++++++ .../MachineLearning/GetJobs/GetJobsApiTests.cs | 10 ++++++++++ .../InvalidateUserAccessTokenApiTests.cs | 15 +++++++++++++-- tests/Tests/XPack/Transform/TransformApiTests.cs | 8 ++++---- 9 files changed, 39 insertions(+), 21 deletions(-) diff --git a/tests/Tests/Cluster/NodesStats/NodesStatsApiTests.cs b/tests/Tests/Cluster/NodesStats/NodesStatsApiTests.cs index de6ae5b0928..132d19b56ae 100644 --- a/tests/Tests/Cluster/NodesStats/NodesStatsApiTests.cs +++ b/tests/Tests/Cluster/NodesStats/NodesStatsApiTests.cs @@ -189,11 +189,7 @@ protected void Assert(ProcessStats process) protected void Assert(ScriptStats script) => script.Should().NotBeNull(); - protected void Assert(ScriptCacheStats scriptCache) - { - scriptCache.Should().NotBeNull(); - scriptCache.Sum.Should().NotBeNull(); - } + protected void Assert(ScriptCacheStats scriptCache) => scriptCache?.Sum.Should().NotBeNull(); protected void Assert(TransportStats transport) => transport.Should().NotBeNull(); diff --git a/tests/Tests/Document/Multiple/DeleteByQuery/DeleteByQueryApiTests.cs b/tests/Tests/Document/Multiple/DeleteByQuery/DeleteByQueryApiTests.cs index f3169cf7ff6..f1589f02b37 100644 --- a/tests/Tests/Document/Multiple/DeleteByQuery/DeleteByQueryApiTests.cs +++ b/tests/Tests/Document/Multiple/DeleteByQuery/DeleteByQueryApiTests.cs @@ -2,7 +2,7 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information -using System; +using System; using System.Collections.Generic; using System.Linq; using Elasticsearch.Net; @@ -211,7 +211,6 @@ protected override void ExpectResponse(DeleteByQueryResponse response) var failure = response.Failures.First(); failure.Index.Should().NotBeNullOrWhiteSpace(); - failure.Type.Should().NotBeNullOrWhiteSpace(); failure.Status.Should().Be(409); failure.Id.Should().NotBeNullOrWhiteSpace(); diff --git a/tests/Tests/Document/Multiple/UpdateByQuery/UpdateByQueryApiTests.cs b/tests/Tests/Document/Multiple/UpdateByQuery/UpdateByQueryApiTests.cs index 083845f1630..46ab63cea9b 100644 --- a/tests/Tests/Document/Multiple/UpdateByQuery/UpdateByQueryApiTests.cs +++ b/tests/Tests/Document/Multiple/UpdateByQuery/UpdateByQueryApiTests.cs @@ -2,7 +2,7 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information -using System; +using System; using System.Linq; using Elastic.Elasticsearch.Xunit.XunitPlumbing; using Elasticsearch.Net; @@ -194,7 +194,6 @@ protected override void ExpectResponse(UpdateByQueryResponse response) var failure = response.Failures.First(); failure.Index.Should().NotBeNullOrWhiteSpace(); - failure.Type.Should().NotBeNullOrWhiteSpace(); failure.Status.Should().Be(409); failure.Id.Should().NotBeNullOrWhiteSpace(); diff --git a/tests/Tests/Mapping/Types/Core/Binary/BinaryPropertyTests.cs b/tests/Tests/Mapping/Types/Core/Binary/BinaryPropertyTests.cs index 85b1bfe4b28..0274c40f1a9 100644 --- a/tests/Tests/Mapping/Types/Core/Binary/BinaryPropertyTests.cs +++ b/tests/Tests/Mapping/Types/Core/Binary/BinaryPropertyTests.cs @@ -22,7 +22,6 @@ public BinaryPropertyTests(WritableCluster cluster, EndpointUsage usage) : base( { type = "binary", doc_values = true, - similarity = "BM25", store = true } } @@ -32,7 +31,6 @@ public BinaryPropertyTests(WritableCluster cluster, EndpointUsage usage) : base( .Binary(b => b .Name(p => p.Name) .DocValues() - .Similarity("BM25") .Store() ); @@ -42,7 +40,6 @@ public BinaryPropertyTests(WritableCluster cluster, EndpointUsage usage) : base( "name", new BinaryProperty { DocValues = true, - Similarity = "BM25", Store = true } } diff --git a/tests/Tests/Mapping/Types/Core/Boolean/BooleanPropertyTests.cs b/tests/Tests/Mapping/Types/Core/Boolean/BooleanPropertyTests.cs index cbc69d19862..2397f6ebc8e 100644 --- a/tests/Tests/Mapping/Types/Core/Boolean/BooleanPropertyTests.cs +++ b/tests/Tests/Mapping/Types/Core/Boolean/BooleanPropertyTests.cs @@ -23,7 +23,6 @@ public BooleanPropertyTests(WritableCluster cluster, EndpointUsage usage) : base type = "boolean", boost = 1.3, doc_values = false, - similarity = "BM25", store = true, index = false, null_value = false, @@ -36,7 +35,6 @@ public BooleanPropertyTests(WritableCluster cluster, EndpointUsage usage) : base .Name(p => p.Name) .Boost(1.3) .DocValues(false) - .Similarity("BM25") .Store() .Index(false) .NullValue(false) @@ -49,7 +47,6 @@ public BooleanPropertyTests(WritableCluster cluster, EndpointUsage usage) : base { DocValues = false, Boost = 1.3, - Similarity = "BM25", Store = true, Index = false, NullValue = false diff --git a/tests/Tests/XPack/MachineLearning/DeleteForecast/DeleteForecastApiTests.cs b/tests/Tests/XPack/MachineLearning/DeleteForecast/DeleteForecastApiTests.cs index fc7ba8dcdf0..83f0bf91406 100644 --- a/tests/Tests/XPack/MachineLearning/DeleteForecast/DeleteForecastApiTests.cs +++ b/tests/Tests/XPack/MachineLearning/DeleteForecast/DeleteForecastApiTests.cs @@ -52,6 +52,15 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues } } + protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values) + { + foreach (var callUniqueValue in values) + { + CloseJob(client, callUniqueValue.Value + "-job"); + DeleteJob(client, callUniqueValue.Value + "-job"); + } + } + protected override LazyResponses ClientUsage() => Calls( (client, f) => client.MachineLearning.DeleteForecast(CallIsolatedValue + "-job", CallIsolatedValue), (client, f) => client.MachineLearning.DeleteForecastAsync(CallIsolatedValue + "-job", CallIsolatedValue), diff --git a/tests/Tests/XPack/MachineLearning/GetJobs/GetJobsApiTests.cs b/tests/Tests/XPack/MachineLearning/GetJobs/GetJobsApiTests.cs index abebc4b8429..0efba33d349 100644 --- a/tests/Tests/XPack/MachineLearning/GetJobs/GetJobsApiTests.cs +++ b/tests/Tests/XPack/MachineLearning/GetJobs/GetJobsApiTests.cs @@ -30,6 +30,11 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues foreach (var callUniqueValue in values) PutJob(client, callUniqueValue.Value); } + protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values) + { + foreach (var callUniqueValue in values) DeleteJob(client, callUniqueValue.Value); + } + protected override LazyResponses ClientUsage() => Calls( (client, f) => client.MachineLearning.GetJobs(f), (client, f) => client.MachineLearning.GetJobsAsync(f), @@ -90,6 +95,11 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues foreach (var callUniqueValue in values) PutJob(client, callUniqueValue.Value); } + protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values) + { + foreach (var callUniqueValue in values) DeleteJob(client, callUniqueValue.Value); + } + protected override LazyResponses ClientUsage() => Calls( (client, f) => client.MachineLearning.GetJobs(f), (client, f) => client.MachineLearning.GetJobsAsync(f), diff --git a/tests/Tests/XPack/Security/User/InvalidateUserAccessToken/InvalidateUserAccessTokenApiTests.cs b/tests/Tests/XPack/Security/User/InvalidateUserAccessToken/InvalidateUserAccessTokenApiTests.cs index d4c4b4004d6..7d80ad749e5 100644 --- a/tests/Tests/XPack/Security/User/InvalidateUserAccessToken/InvalidateUserAccessTokenApiTests.cs +++ b/tests/Tests/XPack/Security/User/InvalidateUserAccessToken/InvalidateUserAccessTokenApiTests.cs @@ -7,6 +7,7 @@ using Elasticsearch.Net; using FluentAssertions; using Nest; +using Tests.Core.Client; using Tests.Core.Extensions; using Tests.Framework.EndpointTests; using Tests.Framework.EndpointTests.TestState; @@ -69,8 +70,18 @@ public InvalidateUserAccessTokenBadPasswordApiTests(Security cluster, EndpointUs protected override string CurrentAccessToken => "bad_password"; protected override bool ExpectIsValid => false; - protected override int ExpectStatusCode => 401; + protected override int ExpectStatusCode => TestClient.Configuration.InRange("<7.8.0") ? 401 : 404; - protected override void ExpectResponse(InvalidateUserAccessTokenResponse response) => response.ServerError.Should().NotBeNull(); + protected override void ExpectResponse(InvalidateUserAccessTokenResponse response) + { + if (TestClient.Configuration.InRange("<7.8.0")) + response.ServerError.Should().NotBeNull(); + else + { + response.InvalidatedTokens.Should().BeGreaterOrEqualTo(0); + response.PreviouslyInvalidatedTokens.Should().BeGreaterOrEqualTo(0); + response.ErrorCount.Should().BeGreaterOrEqualTo(0); + } + } } } diff --git a/tests/Tests/XPack/Transform/TransformApiTests.cs b/tests/Tests/XPack/Transform/TransformApiTests.cs index a32e377bdd0..10f9b13704e 100644 --- a/tests/Tests/XPack/Transform/TransformApiTests.cs +++ b/tests/Tests/XPack/Transform/TransformApiTests.cs @@ -233,8 +233,8 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne { StopTransformStep, u => u.Calls( - v => new StopTransformRequest(v) { Force = true, WaitForCompletion = true }, - (v, d) => d.Force().WaitForCompletion(), + v => new StopTransformRequest(v) { Force = true, WaitForCompletion = true, Timeout = "2m"}, + (v, d) => d.Force().WaitForCompletion().Timeout("2m"), (v, c, f) => c.Transform.Stop(v, f), (v, c, f) => c.Transform.StopAsync(v, f), (v, c, r) => c.Transform.Stop(r), @@ -244,8 +244,8 @@ public TransformApiTests(WritableCluster cluster, EndpointUsage usage) : base(ne { DeleteTransformStep, u => u.Calls( - v => new DeleteTransformRequest(v), - (v, d) => d, + v => new DeleteTransformRequest(v) { Force = true }, + (v, d) => d.Force(), (v, c, f) => c.Transform.Delete(v, f), (v, c, f) => c.Transform.DeleteAsync(v, f), (v, c, r) => c.Transform.Delete(r),