Skip to content

Commit

Permalink
Added a new deprecation logging tests that works for 6.0, test framew…
Browse files Browse the repository at this point in the history
…ork now reports back on all deprecations it sees during the integration test run as well
  • Loading branch information
Mpdreamz committed Nov 16, 2017
1 parent 6a264f5 commit 9c691bb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
36 changes: 29 additions & 7 deletions src/Tests/ClientConcepts/Troubleshooting/DeprecationLogging.doc.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using System.Collections.Generic;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Framework;
using Tests.Framework.ManagedElasticsearch.Clusters;
using Tests.Framework.MockData;
using Xunit;
using static Nest.Infer;

namespace Tests.ClientConcepts.Troubleshooting
{
Expand All @@ -19,16 +23,34 @@ public class DeprecationLogging : IntegrationDocumentationTestBase, IClusterFixt
{
public DeprecationLogging(ReadOnlyCluster cluster) : base(cluster) { }

[I(Skip = "6.0.0-rc1")] public void RequestWithMultipleWarning()
[I] public void RequestWithMultipleWarning()
{
//TODO come up with a new deprecation test since fielddata is gone
throw new NotImplementedException();

var response = this.Client.Search<Project>(s => s);
var request = new SearchRequest<Project>
{
Size = 0,
Routing = new [] { "ignoredefaultcompletedhandler" },
Aggregations = new TermsAggregation("states")
{
Field = Field<Project>(p => p.State.Suffix("keyword")),
Order = new List<TermsOrder>
{
new TermsOrder { Key = "_term", Order = SortOrder.Ascending },
}
},
Query = new FunctionScoreQuery()
{
Query = new MatchAllQuery { },
Functions = new List<IScoreFunction>
{
new RandomScoreFunction {Seed = 1337},
}
}
};
var response = this.Client.Search<Project>(request);

response.ApiCall.DeprecationWarnings.Should().NotBeNullOrEmpty();

response.DebugInformation.Should().Contain("Server indicated deprecations:"); // <1> `DebugInformation` also contains the deprecation warnings
response.ApiCall.DeprecationWarnings.Should().HaveCount(2);
response.DebugInformation.Should().Contain("Deprecated aggregation order key"); // <1> `DebugInformation` also contains the deprecation warnings
}
}
}
16 changes: 14 additions & 2 deletions src/Tests/Framework/TestClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
Expand Down Expand Up @@ -64,6 +65,8 @@ private static ITestConfiguration LoadConfiguration()
? x
: ConnectionConfiguration.DefaultConnectionLimit;

public static ConcurrentBag<string> SeenDeprecations { get; } = new ConcurrentBag<string>();

private static ConnectionSettings DefaultSettings(ConnectionSettings settings) => settings
.DefaultIndex("default-index")
.PrettyJson()
Expand Down Expand Up @@ -97,6 +100,15 @@ private static ConnectionSettings DefaultSettings(ConnectionSettings settings) =
//.PrettyJson()
//TODO make this random
//.EnableHttpCompression()
.OnRequestCompleted(r =>
{
if (!r.DeprecationWarnings.Any()) return;
var q = r.Uri.Query;
if (!string.IsNullOrWhiteSpace(q) && q.Contains("routing=ignoredefaultcompletedhandler")) return;

var method = ExpensiveTestNameForIntegrationTests();
foreach (var d in r.DeprecationWarnings) SeenDeprecations.Add($"{method}: {d}");
})
.OnRequestDataCreated(data => data.Headers.Add("TestMethod", ExpensiveTestNameForIntegrationTests()));

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

private static string ExpensiveTestNameForIntegrationTests()
{
if (!(RunningFiddler && Configuration.RunIntegrationTests)) return "ignore";
if (!Configuration.RunIntegrationTests) return "ignore";

#if DOTNETCORE
return "TODO: Work out how to get test name. Maybe Environment.StackTrace?";
return "UNKNOWN";
#else
var st = new StackTrace();
var types = GetTypes(st);
Expand Down
12 changes: 12 additions & 0 deletions src/Tests/Framework/Xunit/TestFrameworkExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ protected override async void RunTestCases(
Console.WriteLine($"- {kv.Key}: {kv.Value.Elapsed}");
Console.WriteLine("--------");

DumpSeenDeprecations();

if (runner.FailedCollections.Count > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Expand All @@ -53,6 +55,16 @@ protected override async void RunTestCases(
}
}

private static void DumpSeenDeprecations()
{
if (TestClient.SeenDeprecations.Count == 0) return;

Console.WriteLine("-------- SEEN DEPRECATIONS");
foreach (var d in TestClient.SeenDeprecations.Distinct())
Console.WriteLine(d);
Console.WriteLine("--------");
}

private static void DumpReproduceFilters(TestAssemblyRunner runner)
{
var runningIntegrations = TestClient.Configuration.RunIntegrationTests;
Expand Down
1 change: 0 additions & 1 deletion src/Tests/Reproduce/GithubIssue2788.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Child
public TimeSpan EndTime { get; set; }
}

[SkipVersion("6.0.0-rc1", "inner hits will return to their old representation with rc2")]
public void CanDeserializeNumberToTimeSpanInInnerHits()
{
var indexName = "sample";
Expand Down
1 change: 0 additions & 1 deletion src/Tests/Search/Request/InnerHitsUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ protected override LazyResponses ClientUsage() => Calls(
/**[float]
*=== Query Inner Hits
*/
[SkipVersion("6.0.0-rc1", "inner hits will return to their old representation with rc2")]
public class QueryInnerHitsApiTests : InnerHitsApiTestsBase<King>
{
public QueryInnerHitsApiTests(IntrusiveOperationCluster cluster, EndpointUsage usage) : base(cluster, usage)
Expand Down
4 changes: 1 addition & 3 deletions src/Tests/XPack/Watcher/DeleteWatch/DeleteWatchApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ protected override LazyResponses ClientUsage() => Calls(

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

protected override DeleteWatchRequest Initializer =>
new DeleteWatchRequest(CallIsolatedValue);
protected override DeleteWatchRequest Initializer => new DeleteWatchRequest(CallIsolatedValue);

protected override void ExpectResponse(IDeleteWatchResponse response)
{
Expand All @@ -76,7 +75,6 @@ protected override void ExpectResponse(IDeleteWatchResponse response)
}
}

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

0 comments on commit 9c691bb

Please sign in to comment.