Skip to content

Commit 2c8ff4b

Browse files
authored
Fix CatHelp NodeHotThreads integ tests due to mimetype mismatch (#3883)
* content type can now be dictated on the request * improved logging for CoordinatedIntegrationTestBase.cs * SSL warnings on certgen were making xpack tests not run on my windows machine
1 parent 35bf534 commit 2c8ff4b

File tree

14 files changed

+95
-38
lines changed

14 files changed

+95
-38
lines changed

build/scripts/Tooling.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Tooling =
1616
let startArgs = StartArguments(bin, args |> List.toArray)
1717
if (Option.isSome workinDir) then
1818
startArgs.WorkingDirectory <- Option.defaultValue "" workinDir
19-
startArgs.WaitForStreamReadersTimeout <- Nullable<TimeSpan>()
19+
if Commandline.isMono then startArgs.WaitForStreamReadersTimeout <- Nullable<TimeSpan>()
2020
let result = Proc.StartRedirected(startArgs, timeout, LineHighlightWriter())
2121
if not result.Completed then failwithf "process failed to complete within %O: %s" timeout bin
2222
if not result.ExitCode.HasValue then failwithf "process yielded no exit code: %s" bin

build/scripts/scripts.fsproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
</PropertyGroup>
7070
<ItemGroup>
7171
<PackageReference Include="Bullseye" Version="2.4.0-alpha.1" />
72-
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20190621T072151" />
72+
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20190626T161237" />
7373
<PackageReference Include="Fake.Core.Environment" Version="5.15.0" />
7474
<PackageReference Include="Fake.Core.SemVer" Version="5.15.0" />
7575
<PackageReference Include="Fake.IO.FileSystem" Version="5.15.0" />

src/Elasticsearch.Net/Connection/HttpWebRequestConnection.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ static HttpWebRequestConnection()
2020
{
2121
//Not available under mono
2222
if (!IsMono) HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
23+
24+
2325
}
2426

2527
internal static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null;
@@ -244,10 +246,13 @@ protected virtual void SetBasicAuthenticationIfNeeded(HttpWebRequest request, Re
244246
// 2 - Specified at the global IConnectionSettings level
245247
// 3 - Specified with the URI (lowest precedence)
246248

247-
var userInfo = Uri.UnescapeDataString(requestData.Uri.UserInfo);
249+
string userInfo = null;
250+
if (!string.IsNullOrEmpty(requestData.Uri.UserInfo))
251+
userInfo = Uri.UnescapeDataString(requestData.Uri.UserInfo);
252+
else if (requestData.BasicAuthorizationCredentials != null)
253+
userInfo =
254+
$"{requestData.BasicAuthorizationCredentials.Username}:{requestData.BasicAuthorizationCredentials.Password.CreateString()}";
248255

249-
if (requestData.BasicAuthorizationCredentials != null)
250-
userInfo = requestData.BasicAuthorizationCredentials.ToString();
251256

252257
if (!string.IsNullOrWhiteSpace(userInfo))
253258
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userInfo));

src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Elasticsearch.Net
1212
public class RequestData
1313
{
1414
public const string MimeType = "application/json";
15+
public const string MimeTypeTextPlain = "text/plain";
1516
public const string OpaqueIdHeader = "X-Opaque-Id";
1617
public const string RunAsSecurityHeader = "es-security-runas-user";
1718

src/Nest/Cluster/NodesHotThreads/NodesHotThreadsRequest.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Elasticsearch.Net.Specification.NodesApi;
1+
using Elasticsearch.Net;
2+
using Elasticsearch.Net.Specification.NodesApi;
23

34
namespace Nest
45
{
@@ -7,12 +8,16 @@ public partial interface INodesHotThreadsRequest { }
78

89
public partial class NodesHotThreadsRequest
910
{
11+
protected override string ContentType => RequestData.MimeTypeTextPlain;
12+
1013
protected sealed override void RequestDefaults(NodesHotThreadsRequestParameters parameters) =>
1114
parameters.CustomResponseBuilder = NodeHotThreadsResponseBuilder.Instance;
1215
}
1316

1417
public partial class NodesHotThreadsDescriptor
1518
{
19+
protected override string ContentType => RequestData.MimeTypeTextPlain;
20+
1621
protected sealed override void RequestDefaults(NodesHotThreadsRequestParameters parameters) =>
1722
parameters.CustomResponseBuilder = NodeHotThreadsResponseBuilder.Instance;
1823
}

src/Nest/CommonAbstractions/Request/RequestBase.cs

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace Nest
99
[InterfaceDataContract]
1010
public interface IRequest
1111
{
12+
[IgnoreDataMember]
13+
string ContentType { get; }
14+
1215
[IgnoreDataMember]
1316
HttpMethod HttpMethod { get; }
1417

@@ -58,6 +61,10 @@ protected RequestBase(Func<RouteValues, RouteValues> pathSelector)
5861
[IgnoreDataMember]
5962
HttpMethod IRequest.HttpMethod => HttpMethod;
6063

64+
[IgnoreDataMember]
65+
string IRequest.ContentType => ContentType;
66+
protected virtual string ContentType { get; } = null;
67+
6168
private readonly TParameters _parameters;
6269

6370
[IgnoreDataMember]

src/Nest/ElasticClient.cs

+23-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ protected CatResponse<TCatRecord> DoCat<TRequest, TParams, TCatRecord>(TRequest
3838
where TRequest : class, IRequest<TParams>
3939
{
4040
if (typeof(TCatRecord) == typeof(CatHelpRecord))
41+
{
4142
request.RequestParameters.CustomResponseBuilder = CatHelpResponseBuilder.Instance;
42-
else
43-
request.RequestParameters.CustomResponseBuilder = CatResponseBuilder<TCatRecord>.Instance;
43+
return DoRequest<TRequest, CatResponse<TCatRecord>>(request, request.RequestParameters, r => ElasticClient.ForceTextPlain(r));
44+
}
45+
request.RequestParameters.CustomResponseBuilder = CatResponseBuilder<TCatRecord>.Instance;
4446
return DoRequest<TRequest, CatResponse<TCatRecord>>(request, request.RequestParameters, r => ElasticClient.ForceJson(r));
4547
}
4648

@@ -50,9 +52,11 @@ protected Task<CatResponse<TCatRecord>> DoCatAsync<TRequest, TParams, TCatRecord
5052
where TRequest : class, IRequest<TParams>
5153
{
5254
if (typeof(TCatRecord) == typeof(CatHelpRecord))
55+
{
5356
request.RequestParameters.CustomResponseBuilder = CatHelpResponseBuilder.Instance;
54-
else
55-
request.RequestParameters.CustomResponseBuilder = CatResponseBuilder<TCatRecord>.Instance;
57+
return DoRequestAsync<TRequest, CatResponse<TCatRecord>>(request, request.RequestParameters, ct, r => ElasticClient.ForceTextPlain(r));
58+
}
59+
request.RequestParameters.CustomResponseBuilder = CatResponseBuilder<TCatRecord>.Instance;
5660
return DoRequestAsync<TRequest, CatResponse<TCatRecord>>(request, request.RequestParameters, ct, r => ElasticClient.ForceJson(r));
5761
}
5862

@@ -103,6 +107,7 @@ internal TResponse DoRequest<TRequest, TResponse>(TRequest p, IRequestParameters
103107
where TResponse : class, IElasticsearchResponse, new()
104108
{
105109
if (forceConfiguration != null) ForceConfiguration(p, forceConfiguration);
110+
if (p.ContentType != null) ForceContentType(p, p.ContentType);
106111

107112
var url = p.GetUrl(ConnectionSettings);
108113
var b = (p.HttpMethod == HttpMethod.GET || p.HttpMethod == HttpMethod.HEAD) ? null : new SerializableData<TRequest>(p);
@@ -120,6 +125,7 @@ internal Task<TResponse> DoRequestAsync<TRequest, TResponse>(
120125
where TResponse : class, IElasticsearchResponse, new()
121126
{
122127
if (forceConfiguration != null) ForceConfiguration(p, forceConfiguration);
128+
if (p.ContentType != null) ForceContentType(p, p.ContentType);
123129

124130
var url = p.GetUrl(ConnectionSettings);
125131
var b = (p.HttpMethod == HttpMethod.GET || p.HttpMethod == HttpMethod.HEAD) ? null : new SerializableData<TRequest>(p);
@@ -130,16 +136,29 @@ internal Task<TResponse> DoRequestAsync<TRequest, TResponse>(
130136
private static void ForceConfiguration(IRequest request, Action<IRequestConfiguration> forceConfiguration)
131137
{
132138
if (forceConfiguration == null) return;
139+
133140
var configuration = request.RequestParameters.RequestConfiguration ?? new RequestConfiguration();
134141
forceConfiguration(configuration);
135142
request.RequestParameters.RequestConfiguration = configuration;
136143
}
144+
private void ForceContentType<TRequest>(TRequest request, string contentType) where TRequest : class, IRequest
145+
{
146+
var configuration = request.RequestParameters.RequestConfiguration ?? new RequestConfiguration();
147+
configuration.Accept = contentType;
148+
configuration.ContentType = contentType;
149+
request.RequestParameters.RequestConfiguration = configuration;
150+
}
137151

138152
internal static void ForceJson(IRequestConfiguration requestConfiguration)
139153
{
140154
requestConfiguration.Accept = RequestData.MimeType;
141155
requestConfiguration.ContentType = RequestData.MimeType;
142156
}
157+
internal static void ForceTextPlain(IRequestConfiguration requestConfiguration)
158+
{
159+
requestConfiguration.Accept = RequestData.MimeTypeTextPlain;
160+
requestConfiguration.ContentType = RequestData.MimeTypeTextPlain;
161+
}
143162

144163
internal IRequestParameters ResponseBuilder(SourceRequestParameters parameters, CustomResponseBuilderBase builder)
145164
{

src/Tests/Tests.Benchmarking/Tests.Benchmarking.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414
<ItemGroup>
1515
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
16-
<PackageReference Include="Elastic.BenchmarkDotNetExporter" Version="0.1.0-ci20190621T072151" />
16+
<PackageReference Include="Elastic.BenchmarkDotNetExporter" Version="0.1.0-ci20190626T161237" />
1717
<PackageReference Include="LibGit2Sharp" Version="0.26.0-preview-0062" />
1818
</ItemGroup>
1919
</Project>

src/Tests/Tests.Core/Tests.Core.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
</ItemGroup>
1414
<ItemGroup>
1515
<ProjectReference Include="..\Tests.Domain\Tests.Domain.csproj" />
16-
<PackageReference Include="Elastic.Xunit" Version="0.1.0-ci20190621T072151" />
16+
<PackageReference Include="Elastic.Xunit" Version="0.1.0-ci20190626T161237" />
1717
<PackageReference Include="Proc" Version="0.6.1" />
1818
<PackageReference Include="xunit" Version="2.3.1" />
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
2020
<PackageReference Include="FluentAssertions" Version="5.7.0" />
2121
<PackageReference Include="DiffPlex" Version="1.4.1" />
2222
</ItemGroup>

src/Tests/Tests.Domain/Tests.Domain.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ItemGroup>
1313
<ItemGroup>
1414
<PackageReference Include="Bogus" Version="22.1.2" />
15-
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20190621T072151" />
15+
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20190626T161237" />
1616
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
1717
<ProjectReference Include="..\Tests.Configuration\Tests.Configuration.csproj" />
1818
</ItemGroup>

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

+16-17
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ namespace Tests.ClientConcepts.Troubleshooting
2626
*
2727
* To aid with their discover the topics you can subscribe on and the event names they emit are exposed as
2828
* strongly typed strings under `Elasticsearch.Net.Diagnostics.DiagnosticSources`
29-
*
29+
*
3030
*/
3131
public class DiagnosticSourceUsageDocumentation : IClusterFixture<ReadOnlyCluster>
3232
{
3333
private readonly ReadOnlyCluster _cluster;
3434

3535
public DiagnosticSourceUsageDocumentation(ReadOnlyCluster cluster) => _cluster = cluster;
36-
37-
36+
37+
3838
/**
3939
* Subscribing to DiagnosticSources means implementing `IObserver<DiagnosticListener>`
4040
* or use `.Subscribe(observer, filter)` to opt in to the correct topic.
4141
*
4242
* Here we choose the more verbose `IObserver<>` implementation.
43-
*
43+
*
4444
*/
4545
private class ListenerObserver : IObserver<DiagnosticListener>, IDisposable
4646
{
4747
private long _messagesWrittenToConsole = 0;
4848
public long MessagesWrittenToConsole => _messagesWrittenToConsole;
49-
49+
5050
public Exception SeenException { get; private set; }
5151
public void OnError(Exception error) => SeenException = error;
5252

@@ -56,12 +56,11 @@ private class ListenerObserver : IObserver<DiagnosticListener>, IDisposable
5656
private void WriteToConsole<T>(string eventName, T data)
5757
{
5858
var a = Activity.Current;
59-
Console.WriteLine($"{eventName?.PadRight(30)} {a.Id?.PadRight(32)} {a.ParentId?.PadRight(32)} {data?.ToString().PadRight(10)}");
6059
Interlocked.Increment(ref _messagesWrittenToConsole);
6160
}
62-
61+
6362
private List<IDisposable> Disposables { get; } = new List<IDisposable>();
64-
63+
6564
/**
6665
* By inspecting the name we selectively subscribe only to topics `Elasticsearch.Net` emits.
6766
*
@@ -72,7 +71,7 @@ private void WriteToConsole<T>(string eventName, T data)
7271
*
7372
* Therefor each topic we ship with has a dedicated `Observer` implementation that takes an `onNext` lambda
7473
* which is typed to the context object we actually emit.
75-
*
74+
*
7675
*/
7776
public void OnNext(DiagnosticListener value)
7877
{
@@ -83,24 +82,24 @@ void TrySubscribe(string sourceName, Func<IObserver<KeyValuePair<string, object>
8382
var subscription = value.Subscribe(listener());
8483
Disposables.Add(subscription);
8584
}
86-
87-
TrySubscribe(DiagnosticSources.AuditTrailEvents.SourceName,
85+
86+
TrySubscribe(DiagnosticSources.AuditTrailEvents.SourceName,
8887
() => new AuditDiagnosticObserver(v => WriteToConsole(v.EventName, v.Audit)));
89-
90-
TrySubscribe(DiagnosticSources.Serializer.SourceName,
88+
89+
TrySubscribe(DiagnosticSources.Serializer.SourceName,
9190
() => new SerializerDiagnosticObserver(v => WriteToConsole(v.EventName, v.Registration)));
9291
/**
9392
* RequestPipeline emits a different context object for the start of the `Activity` then it does
9493
* for the end of the `Activity` therefor `RequestPipelineDiagnosticObserver` accepts two `onNext` lambda's.
9594
* One for the `.Start` events and one for the `.Stop` events.
9695
*/
97-
TrySubscribe(DiagnosticSources.RequestPipeline.SourceName,
96+
TrySubscribe(DiagnosticSources.RequestPipeline.SourceName,
9897
() => new RequestPipelineDiagnosticObserver(
9998
v => WriteToConsole(v.EventName, v.RequestData),
10099
v => WriteToConsole(v.EventName, v.Response)
101100
));
102-
103-
TrySubscribe(DiagnosticSources.HttpConnection.SourceName,
101+
102+
TrySubscribe(DiagnosticSources.HttpConnection.SourceName,
104103
() => new HttpConnectionDiagnosticObserver(
105104
v => WriteToConsole(v.EventName, v.RequestData),
106105
v => WriteToConsole(v.EventName, v.StatusCode)
@@ -122,7 +121,7 @@ [I] public void SubscribeToTopics()
122121
using(var listenerObserver = new ListenerObserver())
123122
using (var subscription = DiagnosticListener.AllListeners.Subscribe(listenerObserver))
124123
{
125-
124+
126125
/**
127126
* We'll use a Sniffing connection pool here since it sniffs on startup and pings before
128127
* first usage, so our diagnostics are involved enough to showcase most topics.

src/Tests/Tests/Framework/EndpointTests/CoordinatedIntegrationTestBase.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.ExceptionServices;
24
using System.Threading.Tasks;
35
using Elastic.Managed.Ephemeral;
46
using Elastic.Xunit.XunitPlumbing;
7+
using Elasticsearch.Net;
58
using Nest;
9+
using Tests.Core.Client;
610
using Tests.Core.ManagedElasticsearch.Clusters;
711
using Tests.Framework.EndpointTests.TestState;
812
using Tests.Framework.Extensions;
@@ -53,7 +57,23 @@ private async Task AssertOnAllResponses<TResponse>(string name, LazyResponses re
5357
if (!_coordinatedUsage.MethodIsolatedValues.TryGetValue(key, out var isolatedValue))
5458
throw new Exception($"{name} is not a request observed and so no call isolated values could be located for it");
5559

56-
assert(isolatedValue, response);
60+
var r = response;
61+
if (TestClient.Configuration.RunIntegrationTests && !r.IsValid && r.ApiCall.OriginalException != null
62+
&& !(r.ApiCall.OriginalException is ElasticsearchClientException))
63+
{
64+
var e = ExceptionDispatchInfo.Capture(r.ApiCall.OriginalException.Demystify());
65+
throw new ResponseAssertionException(e.SourceException, r).Demystify();
66+
}
67+
68+
try
69+
{
70+
assert(isolatedValue, response);
71+
}
72+
catch (Exception e)
73+
{
74+
var ex = ExceptionDispatchInfo.Capture(e.Demystify());
75+
throw new ResponseAssertionException(ex.SourceException, r).Demystify();
76+
}
5777
}
5878
}
5979

src/Tests/Tests/Indices/IndexManagement/RolloverIndex/RolloverIndexApiTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public RolloverIndexApiTests(WritableCluster cluster, EndpointUsage usage)
5353
}
5454
}
5555
},
56-
aliases = new
56+
aliases = new Dictionary<string, object>
5757
{
58-
new_projects = new { }
58+
{ CallIsolatedValue + "-new_projects", new { } }
5959
}
6060
};
6161

@@ -83,7 +83,7 @@ public RolloverIndexApiTests(WritableCluster cluster, EndpointUsage usage)
8383
)
8484
)
8585
.Aliases(a => a
86-
.Alias("new_projects")
86+
.Alias(CallIsolatedValue + "-new_projects")
8787
);
8888

8989
protected override RolloverIndexRequest Initializer => new RolloverIndexRequest(CallIsolatedValue + "-alias", CallIsolatedValue + "-new")
@@ -120,7 +120,7 @@ public RolloverIndexApiTests(WritableCluster cluster, EndpointUsage usage)
120120
},
121121
Aliases = new Aliases
122122
{
123-
{ "new_projects", new Alias() }
123+
{ CallIsolatedValue + "-new_projects", new Alias() }
124124
}
125125
};
126126

@@ -138,7 +138,7 @@ protected override void OnBeforeCall(IElasticClient client)
138138
.IndexMany(Project.Generator.Generate(1200))
139139
);
140140
someDocs.ShouldBeValid();
141-
141+
142142
}
143143

144144
protected override LazyResponses ClientUsage() => Calls(

src/Tests/Tests/XPack/Security/User/PutUser/PutUserApiTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ protected override LazyResponses ClientUsage() => Calls(
7272

7373
protected override PutUserDescriptor NewDescriptor() => new PutUserDescriptor(CallIsolatedValue);
7474

75-
protected override void ExpectResponse(PutUserResponse response) => response.Created.Should().BeTrue();
75+
protected override void ExpectResponse(PutUserResponse response) =>
76+
response.Created.Should().BeTrue("{0}", response.DebugInformation);
7677
}
7778

7879
public class PutUserRunAsApiTests : PutUserApiTests

0 commit comments

Comments
 (0)