Skip to content

Commit 1ea570b

Browse files
committed
Added a new deprecation logging tests that works for 6.0, test framework now reports back on all deprecations it sees during the integration test run as well
1 parent aec072b commit 1ea570b

File tree

6 files changed

+56
-14
lines changed

6 files changed

+56
-14
lines changed

src/Tests/ClientConcepts/Troubleshooting/DeprecationLogging.doc.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
2+
using System.Collections.Generic;
3+
using Elasticsearch.Net;
24
using FluentAssertions;
5+
using Nest;
36
using Tests.Framework;
47
using Tests.Framework.ManagedElasticsearch.Clusters;
58
using Tests.Framework.MockData;
69
using Xunit;
10+
using static Nest.Infer;
711

812
namespace Tests.ClientConcepts.Troubleshooting
913
{
@@ -19,16 +23,34 @@ public class DeprecationLogging : IntegrationDocumentationTestBase, IClusterFixt
1923
{
2024
public DeprecationLogging(ReadOnlyCluster cluster) : base(cluster) { }
2125

22-
[I(Skip = "6.0.0-rc1")] public void RequestWithMultipleWarning()
26+
[I] public void RequestWithMultipleWarning()
2327
{
24-
//TODO come up with a new deprecation test since fielddata is gone
25-
throw new NotImplementedException();
26-
27-
var response = this.Client.Search<Project>(s => s);
28+
var request = new SearchRequest<Project>
29+
{
30+
Size = 0,
31+
Routing = new [] { "ignoredefaultcompletedhandler" },
32+
Aggregations = new TermsAggregation("states")
33+
{
34+
Field = Field<Project>(p => p.State.Suffix("keyword")),
35+
Order = new List<TermsOrder>
36+
{
37+
new TermsOrder { Key = "_term", Order = SortOrder.Ascending },
38+
}
39+
},
40+
Query = new FunctionScoreQuery()
41+
{
42+
Query = new MatchAllQuery { },
43+
Functions = new List<IScoreFunction>
44+
{
45+
new RandomScoreFunction {Seed = 1337},
46+
}
47+
}
48+
};
49+
var response = this.Client.Search<Project>(request);
2850

2951
response.ApiCall.DeprecationWarnings.Should().NotBeNullOrEmpty();
30-
31-
response.DebugInformation.Should().Contain("Server indicated deprecations:"); // <1> `DebugInformation` also contains the deprecation warnings
52+
response.ApiCall.DeprecationWarnings.Should().HaveCount(2);
53+
response.DebugInformation.Should().Contain("Deprecated aggregation order key"); // <1> `DebugInformation` also contains the deprecation warnings
3254
}
3355
}
3456
}

src/Tests/Framework/TestClient.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Collections.Specialized;
45
using System.Diagnostics;
@@ -64,6 +65,8 @@ private static ITestConfiguration LoadConfiguration()
6465
? x
6566
: ConnectionConfiguration.DefaultConnectionLimit;
6667

68+
public static ConcurrentBag<string> SeenDeprecations { get; } = new ConcurrentBag<string>();
69+
6770
private static ConnectionSettings DefaultSettings(ConnectionSettings settings) => settings
6871
.DefaultIndex("default-index")
6972
.PrettyJson()
@@ -97,6 +100,15 @@ private static ConnectionSettings DefaultSettings(ConnectionSettings settings) =
97100
//.PrettyJson()
98101
//TODO make this random
99102
//.EnableHttpCompression()
103+
.OnRequestCompleted(r =>
104+
{
105+
if (!r.DeprecationWarnings.Any()) return;
106+
var q = r.Uri.Query;
107+
if (!string.IsNullOrWhiteSpace(q) && q.Contains("routing=ignoredefaultcompletedhandler")) return;
108+
109+
var method = ExpensiveTestNameForIntegrationTests();
110+
foreach (var d in r.DeprecationWarnings) SeenDeprecations.Add($"{method}: {d}");
111+
})
100112
.OnRequestDataCreated(data => data.Headers.Add("TestMethod", ExpensiveTestNameForIntegrationTests()));
101113

102114
public static string PercolatorType => Configuration.ElasticsearchVersion <= ElasticsearchVersion.GetOrAdd("5.0.0-alpha1")
@@ -183,10 +195,10 @@ public static IElasticClient GetFixedReturnClient(
183195

184196
private static string ExpensiveTestNameForIntegrationTests()
185197
{
186-
if (!(RunningFiddler && Configuration.RunIntegrationTests)) return "ignore";
198+
if (!Configuration.RunIntegrationTests) return "ignore";
187199

188200
#if DOTNETCORE
189-
return "TODO: Work out how to get test name. Maybe Environment.StackTrace?";
201+
return "UNKNOWN";
190202
#else
191203
var st = new StackTrace();
192204
var types = GetTypes(st);

src/Tests/Framework/Xunit/TestFrameworkExecutor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ protected override async void RunTestCases(
3232
Console.WriteLine($"- {kv.Key}: {kv.Value.Elapsed}");
3333
Console.WriteLine("--------");
3434

35+
DumpSeenDeprecations();
36+
3537
if (runner.FailedCollections.Count > 0)
3638
{
3739
Console.ForegroundColor = ConsoleColor.Red;
@@ -53,6 +55,16 @@ protected override async void RunTestCases(
5355
}
5456
}
5557

58+
private static void DumpSeenDeprecations()
59+
{
60+
if (TestClient.SeenDeprecations.Count == 0) return;
61+
62+
Console.WriteLine("-------- SEEN DEPRECATIONS");
63+
foreach (var d in TestClient.SeenDeprecations.Distinct())
64+
Console.WriteLine(d);
65+
Console.WriteLine("--------");
66+
}
67+
5668
private static void DumpReproduceFilters(TestAssemblyRunner runner)
5769
{
5870
var runningIntegrations = TestClient.Configuration.RunIntegrationTests;

src/Tests/Reproduce/GithubIssue2788.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class Child
3434
public TimeSpan EndTime { get; set; }
3535
}
3636

37-
[SkipVersion("6.0.0-rc1", "inner hits will return to their old representation with rc2")]
3837
public void CanDeserializeNumberToTimeSpanInInnerHits()
3938
{
4039
var indexName = "sample";

src/Tests/Search/Request/InnerHitsUsageTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ protected override LazyResponses ClientUsage() => Calls(
198198
/**[float]
199199
*=== Query Inner Hits
200200
*/
201-
[SkipVersion("6.0.0-rc1", "inner hits will return to their old representation with rc2")]
202201
public class QueryInnerHitsApiTests : InnerHitsApiTestsBase<King>
203202
{
204203
public QueryInnerHitsApiTests(IntrusiveOperationCluster cluster, EndpointUsage usage) : base(cluster, usage)

src/Tests/XPack/Watcher/DeleteWatch/DeleteWatchApiTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ protected override LazyResponses ClientUsage() => Calls(
6565

6666
protected override Func<DeleteWatchDescriptor, IDeleteWatchRequest> Fluent => p => p;
6767

68-
protected override DeleteWatchRequest Initializer =>
69-
new DeleteWatchRequest(CallIsolatedValue);
68+
protected override DeleteWatchRequest Initializer => new DeleteWatchRequest(CallIsolatedValue);
7069

7170
protected override void ExpectResponse(IDeleteWatchResponse response)
7271
{
@@ -76,7 +75,6 @@ protected override void ExpectResponse(IDeleteWatchResponse response)
7675
}
7776
}
7877

79-
[SkipVersion("6.0.0-rc1", "Delete document response on non existing index has changed")]
8078
public class DeleteNonExistentWatchApiTests : ApiIntegrationTestBase<XPackCluster, IDeleteWatchResponse, IDeleteWatchRequest, DeleteWatchDescriptor, DeleteWatchRequest>
8179
{
8280
public DeleteNonExistentWatchApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

0 commit comments

Comments
 (0)