Skip to content

Commit 98ceaf6

Browse files
Mpdreamzrusscam
authored andcommitted
Feature/7.x/virtual connection (#3908)
* rename Serializer subfolder to Auxiliary * introduced seperate project for virtual cluster * VirtualCluster auditor returns a more real fake response * moved WaitingInMemoryConnection back * Union was copied twice * make sure VirtualClusterConnection is exposed * Add Elasticsearch.Net.Virtual as project into the build * do not rely on HttpClientException on net461 * Exception test needs to be .NET core specific now * build for canary was still looking in Serializers folder not Auxiliary * canary handling for Elasticsearch.Net.Virtual * skip nuget testing for Elasticearch.Net.Virtual * reference TestPackageVersion of Elasticsearch.Net optionally * still included csproj * Use targetting pack and made sure canary works under linux too * Update build/Elasticsearch.Net.Virtual.nuspec Co-Authored-By: Russ Cam <[email protected]> * Client on VirtualizedCluster became public on 7.x, mirror that here * change namespace to Elasticsearch.Net.VirtualizedCluster * update tests from 7.x and bumped sdk version * bump global json back * canary build needs to resolve Elasticsearch.Net reference as nuget for virtualized cluster project * bulk all exception tests canary ignore * bulk all exception tests canary ignore * make test less strict * skip test on CI
1 parent 0dd5cb2 commit 98ceaf6

File tree

70 files changed

+577
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+577
-367
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>Elasticsearch.Net.VirtualizedCluster</id>
5+
<version>$version$</version>
6+
<title>Elasticsearch.Net.VirtualizedCluster - A highly configurable in memory IConnection</title>
7+
<authors>Elastic and contributors</authors>
8+
<owners>Elastic</owners>
9+
<license type="file">license.txt</license>
10+
<projectUrl>https://github.com/elastic/elasticsearch-net</projectUrl>
11+
<iconUrl>https://raw.githubusercontent.com/elastic/elasticsearch-net/master/build/nuget-icon.png</iconUrl>
12+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
13+
<summary>Provides a way to assert client behaviour through a rule engine backed VirtualClusterConnection</summary>
14+
<description>Provides a way to assert cluent behaviour through a rule engine backed VirtualClusterConnection</description>
15+
<releaseNotes>See https://github.com/elastic/elasticsearch-net/releases/tag/$version$</releaseNotes>
16+
<copyright>2014-$year$ Elasticsearch BV</copyright>
17+
<tags>elasticsearch,elastic,search,lucene,nest</tags>
18+
<dependencies>
19+
<group targetFramework=".NETStandard2.0">
20+
<dependency id="Elasticsearch.Net" version="[$currentMajorVersion$, $nextMajorVersion$)" />
21+
</group>
22+
<group targetFramework="net461">
23+
<dependency id="Elasticsearch.Net" version="[$currentMajorVersion$, $nextMajorVersion$)" />
24+
</group>
25+
</dependencies>
26+
</metadata>
27+
<files>
28+
<file src="..\license.txt" target="" />
29+
30+
<file src="output\Elasticsearch.Net.VirtualizedCluster\netstandard2.0\Elasticsearch.Net.VirtualizedCluster.dll" target="lib\netstandard2.0"/>
31+
<file src="output\Elasticsearch.Net.VirtualizedCluster\netstandard2.0\Elasticsearch.Net.VirtualizedCluster.xml" target="lib\netstandard2.0"/>
32+
33+
<file src="output\Elasticsearch.Net.VirtualizedCluster\net461\Elasticsearch.Net.VirtualizedCluster.dll" target="lib\net461"/>
34+
<file src="output\Elasticsearch.Net.VirtualizedCluster\net461\Elasticsearch.Net.VirtualizedCluster.xml" target="lib\net461"/>
35+
</files>
36+
</package>

build/scripts/Paths.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ module Paths =
3333
match project with
3434
| Project p ->
3535
match p with
36-
| NestJsonNetSerializer -> sprintf "%s/Serializers/%s/%s.csproj" SourceFolder project.Name project.Name
36+
| NestJsonNetSerializer -> sprintf "%s/Auxiliary/%s/%s.csproj" SourceFolder project.Name project.Name
37+
| ElasticsearchNetVirtual -> sprintf "%s/Auxiliary/%s/%s.csproj" SourceFolder project.Name project.Name
3738
| _ -> sprintf "%s/%s/%s.csproj" SourceFolder project.Name project.Name
3839
| PrivateProject p ->
3940
match p with

build/scripts/Projects.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Projects =
2020
| Nest
2121
| ElasticsearchNet
2222
| NestJsonNetSerializer
23+
| ElasticsearchNetVirtual
2324

2425
type PrivateProject =
2526
| Tests
@@ -39,6 +40,7 @@ module Projects =
3940
Project Project.ElasticsearchNet;
4041
Project Project.Nest;
4142
Project Project.NestJsonNetSerializer;
43+
Project Project.ElasticsearchNetVirtual;
4244
PrivateProject PrivateProject.Tests
4345
]
4446

@@ -47,6 +49,7 @@ module Projects =
4749
Project Project.ElasticsearchNet;
4850
Project Project.Nest;
4951
Project Project.NestJsonNetSerializer;
52+
Project Project.ElasticsearchNetVirtual;
5053
]
5154
static member Tests = seq [PrivateProject PrivateProject.Tests]
5255

@@ -67,6 +70,7 @@ module Projects =
6770
| Project Nest -> "Nest"
6871
| Project ElasticsearchNet -> "Elasticsearch.Net"
6972
| Project NestJsonNetSerializer -> "Nest.JsonNetSerializer"
73+
| Project ElasticsearchNetVirtual -> "Elasticsearch.Net.VirtualizedCluster"
7074
| PrivateProject Tests -> "Tests"
7175
| PrivateProject DocGenerator -> "DocGenerator"
7276
| PrivateProject ApiGenerator -> "ApiGenerator"

build/scripts/Releasing.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ module Release =
9797
)
9898

9999
match p with
100+
| Project ElasticsearchNetVirtual
100101
| Project Nest ->
101102
let esDeps = doc.XPathSelectElements("/x:package/x:metadata//x:dependency[@id='Elasticsearch.Net']", nsManager);
102103
esDeps |> Seq.iter(fun e ->
@@ -143,6 +144,9 @@ module Release =
143144

144145
let private nugetPackVersioned (p:DotNetProject) nugetId nuspec properties version =
145146
match p with
147+
| Project ElasticsearchNetVirtual ->
148+
printfn "Skipping %s from building a versioned nightly" p.Name
149+
ignore()
146150
| _ -> nugetPackVersionedUnfiltered p nugetId nuspec properties version
147151

148152
let NugetPack (ArtifactsVersion(version)) = packProjects version nugetPackMain

build/scripts/Targets.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ module Main =
6666
target "inherit-doc" <| InheritDoc.PatchInheritDocs
6767

6868
target "test-nuget-package" <| fun _ ->
69-
//run release unit tests puts packages in the system cache prevent this from happening locally
69+
// run release unit tests puts packages in the system cache prevent this from happening locally
7070
if not Commandline.runningOnCi then ignore ()
7171
else Tests.RunReleaseUnitTests artifactsVersion |> ignore
7272

7373
target "nuget-pack" <| fun _ -> Release.NugetPack artifactsVersion
7474

75-
conditional (parsed.Target = "canary") "nuget-pack-versioned" <| fun _ -> Release.NugetPackVersioned artifactsVersion
75+
conditional (parsed.Target = "canary" && not isMono) "nuget-pack-versioned" <| fun _ -> Release.NugetPackVersioned artifactsVersion
7676

7777
conditional (parsed.Target <> "canary") "generate-release-notes" <| fun _ -> ReleaseNotes.GenerateNotes buildVersions
7878

build/scripts/scripts.fsproj

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,6 @@
2929
<Content Include="..\..\appveyor.yml"><Link>appveyor.yml</Link></Content>
3030
<Content Include="..\..\azure-pipelines.yml"><Link>azure-pipelines.yml</Link></Content>
3131
</ItemGroup>
32-
<!-- Type providers currently can't run inside the .NET Core 2.0 hosted compiler, see https://github.com/Microsoft/visualfsharp/pull/3658#issuecomment-334773415 -->
33-
<PropertyGroup>
34-
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
35-
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
36-
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
37-
</PropertyGroup>
38-
<PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\fsc.exe')">
39-
<FscToolPath>C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0</FscToolPath>
40-
<FscToolExe>fsc.exe</FscToolExe>
41-
</PropertyGroup>
42-
<PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsc.exe')">
43-
<FscToolPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\FSharp</FscToolPath>
44-
<FscToolExe>fsc.exe</FscToolExe>
45-
</PropertyGroup>
46-
<PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsc.exe')">
47-
<FscToolPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp</FscToolPath>
48-
<FscToolExe>fsc.exe</FscToolExe>
49-
</PropertyGroup>
50-
<PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsc.exe')">
51-
<FscToolPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp</FscToolPath>
52-
<FscToolExe>fsc.exe</FscToolExe>
53-
</PropertyGroup>
54-
<PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsc.exe')">
55-
<FscToolPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\FSharp</FscToolPath>
56-
<FscToolExe>fsc.exe</FscToolExe>
57-
</PropertyGroup>
58-
<PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0\fsc.exe')">
59-
<FscToolPath>C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0</FscToolPath>
60-
<FscToolExe>fsc.exe</FscToolExe>
61-
</PropertyGroup>
62-
<PropertyGroup Condition="'$(IsOSX)' == 'true' AND Exists('/Library/Frameworks/Mono.framework/Versions/Current/Commands/fsharpc')">
63-
<FscToolPath>/Library/Frameworks/Mono.framework/Versions/Current/Commands</FscToolPath>
64-
<FscToolExe>fsharpc</FscToolExe>
65-
</PropertyGroup>
66-
<PropertyGroup Condition="'$(IsLinux)' == 'true' AND Exists('/usr/bin/fsharpc')">
67-
<FscToolPath>/usr/bin</FscToolPath>
68-
<FscToolExe>fsharpc</FscToolExe>
69-
</PropertyGroup>
7032
<ItemGroup>
7133
<PackageReference Include="Bullseye" Version="3.0.0-rc.1" />
7234
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20190806T115008" />

src/Tests/Tests/Framework/VirtualClustering/Audit/Auditor.cs renamed to src/Auxiliary/Elasticsearch.Net.VirtualizedCluster/Audit/Auditor.cs

Lines changed: 75 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6-
using Elasticsearch.Net;
7-
using Elasticsearch.Net.Extensions;
8-
using FluentAssertions;
9-
using Nest;
10-
using Tests.Core.Extensions;
11-
using Tests.Framework.Extensions;
12-
13-
namespace Tests.Framework.VirtualClustering.Audit
6+
using Elasticsearch.Net.VirtualizedCluster.Extensions;
7+
8+
namespace Elasticsearch.Net.VirtualizedCluster.Audit
149
{
1510
public class Auditor
1611
{
@@ -36,8 +31,8 @@ private Auditor(VirtualizedCluster cluster, VirtualizedCluster clusterAsync)
3631
public List<Elasticsearch.Net.Audit> AuditTrail { get; set; }
3732
public Func<VirtualizedCluster> Cluster { get; set; }
3833

39-
public IResponse Response { get; internal set; }
40-
public IResponse ResponseAsync { get; internal set; }
34+
public IElasticsearchResponse Response { get; internal set; }
35+
public IElasticsearchResponse ResponseAsync { get; internal set; }
4136

4237
private bool StartedUp { get; }
4338

@@ -66,7 +61,7 @@ public async Task<Auditor> TraceStartup(ClientCall callTrace = null)
6661
_clusterAsync = _clusterAsync ?? Cluster();
6762
if (!StartedUp) AssertPoolBeforeStartup?.Invoke(_clusterAsync.ConnectionPool);
6863
AssertPoolBeforeCall?.Invoke(_clusterAsync.ConnectionPool);
69-
ResponseAsync = await _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides);
64+
ResponseAsync = await _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides).ConfigureAwait(false);
7065
AsyncAuditTrail = ResponseAsync.ApiCall.AuditTrail;
7166
if (!StartedUp) AssertPoolAfterStartup?.Invoke(_clusterAsync.ConnectionPool);
7267
AssertPoolAfterCall?.Invoke(_clusterAsync.ConnectionPool);
@@ -75,7 +70,7 @@ public async Task<Auditor> TraceStartup(ClientCall callTrace = null)
7570

7671
public async Task<Auditor> TraceCall(ClientCall callTrace, int nthCall = 0)
7772
{
78-
await TraceStartup(callTrace);
73+
await TraceStartup(callTrace).ConfigureAwait(false);
7974
return AssertAuditTrails(callTrace, nthCall);
8075
}
8176

@@ -89,18 +84,16 @@ private async Task TraceException<TException>(ClientCall callTrace, Action<TExce
8984
AssertPoolBeforeCall?.Invoke(_cluster.ConnectionPool);
9085

9186
Action call = () => _cluster.ClientCall(callTrace?.RequestOverrides);
92-
var exception = call.Should().ThrowExactly<TException>()
93-
.Subject.First();
87+
var exception = TryCall(call, assert);
9488
assert(exception);
9589

9690
AuditTrail = exception.AuditTrail;
9791
AssertPoolAfterCall?.Invoke(_cluster.ConnectionPool);
9892

9993
_clusterAsync = _clusterAsync ?? Cluster();
10094
_clusterAsync.ClientThrows(true);
101-
Func<Task> callAsync = async () => await _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides);
102-
exception = callAsync.Should().ThrowExactly<TException>()
103-
.Subject.First();
95+
Func<Task> callAsync = () => _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides);
96+
exception = await TryCallAsync(callAsync, assert).ConfigureAwait(false);
10497
assert(exception);
10598

10699
AsyncAuditTrail = exception.AuditTrail;
@@ -109,14 +102,14 @@ private async Task TraceException<TException>(ClientCall callTrace, Action<TExce
109102

110103
public async Task<Auditor> TraceElasticsearchException(ClientCall callTrace, Action<ElasticsearchClientException> assert)
111104
{
112-
await TraceException(callTrace, assert);
105+
await TraceException(callTrace, assert).ConfigureAwait(false);
113106
var audit = new Auditor(_cluster, _clusterAsync);
114-
return await audit.TraceElasticsearchExceptionOnResponse(callTrace, assert);
107+
return await audit.TraceElasticsearchExceptionOnResponse(callTrace, assert).ConfigureAwait(false);
115108
}
116109

117110
public async Task<Auditor> TraceUnexpectedElasticsearchException(ClientCall callTrace, Action<UnexpectedElasticsearchClientException> assert)
118111
{
119-
await TraceException(callTrace, assert);
112+
await TraceException(callTrace, assert).ConfigureAwait(false);
120113
return new Auditor(_cluster, _clusterAsync);
121114
}
122115

@@ -129,23 +122,24 @@ public async Task<Auditor> TraceElasticsearchExceptionOnResponse(ClientCall call
129122
AssertPoolBeforeCall?.Invoke(_cluster.ConnectionPool);
130123

131124
Action call = () => { Response = _cluster.ClientCall(callTrace?.RequestOverrides); };
132-
call.Should().NotThrow();
133-
134-
Response.ShouldNotBeValid();
125+
call();
126+
127+
if (Response.ApiCall.Success) throw new Exception("Expected call to not be valid");
128+
135129
var exception = Response.ApiCall.OriginalException as ElasticsearchClientException;
136-
exception.Should().NotBeNull("OriginalException on response is not expected ElasticsearchClientException");
130+
if (exception == null) throw new Exception("OriginalException on response is not expected ElasticsearchClientException");
137131
assert(exception);
138132

139133
AuditTrail = exception.AuditTrail;
140134
AssertPoolAfterCall?.Invoke(_cluster.ConnectionPool);
141135

142136
_clusterAsync = _clusterAsync ?? Cluster();
143137
_clusterAsync.ClientThrows(false);
144-
Func<Task> callAsync = async () => { ResponseAsync = await _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides); };
145-
callAsync.Should().NotThrow();
146-
ResponseAsync.ShouldNotBeValid();
138+
Func<Task> callAsync = async () => { ResponseAsync = await _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides).ConfigureAwait(false); };
139+
await callAsync().ConfigureAwait(false);
140+
if (Response.ApiCall.Success) throw new Exception("Expected call to not be valid");
147141
exception = ResponseAsync.ApiCall.OriginalException as ElasticsearchClientException;
148-
exception.Should().NotBeNull("OriginalException on response is not expected ElasticsearchClientException");
142+
if (exception == null) throw new Exception("OriginalException on response is not expected ElasticsearchClientException");
149143
assert(exception);
150144

151145
AsyncAuditTrail = exception.AuditTrail;
@@ -163,17 +157,15 @@ public async Task<Auditor> TraceUnexpectedException(ClientCall callTrace, Action
163157
AssertPoolBeforeCall?.Invoke(_cluster.ConnectionPool);
164158

165159
Action call = () => _cluster.ClientCall(callTrace?.RequestOverrides);
166-
var exception = call.Should().ThrowExactly<UnexpectedElasticsearchClientException>()
167-
.Subject.First();
160+
var exception = TryCall(call, assert);
168161
assert(exception);
169162

170163
AuditTrail = exception.AuditTrail;
171164
AssertPoolAfterCall?.Invoke(_cluster.ConnectionPool);
172165

173166
_clusterAsync = _clusterAsync ?? Cluster();
174-
Func<Task> callAsync = async () => await _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides);
175-
exception = callAsync.Should().ThrowExactly<UnexpectedElasticsearchClientException>()
176-
.Subject.First();
167+
Func<Task> callAsync = () => _clusterAsync.ClientCallAsync(callTrace?.RequestOverrides);
168+
exception = await TryCallAsync(callAsync, assert).ConfigureAwait(false);
177169
assert(exception);
178170

179171
AsyncAuditTrail = exception.AuditTrail;
@@ -183,10 +175,9 @@ public async Task<Auditor> TraceUnexpectedException(ClientCall callTrace, Action
183175

184176
private Auditor AssertAuditTrails(ClientCall callTrace, int nthCall)
185177
{
186-
AuditTrail.Count.Should()
187-
.Be(AsyncAuditTrail.Count,
188-
$"{nthCall} has a mismatch between sync and async. \r\nasync:{AuditTrail}\r\nsync:{AsyncAuditTrail}");
189-
178+
if (AuditTrail.Count != AsyncAuditTrail.Count)
179+
throw new Exception($"{nthCall} has a mismatch between sync and async. \r\nasync:{AuditTrail}\r\nsync:{AsyncAuditTrail}");
180+
190181
AssertTrailOnResponse(callTrace, AuditTrail, true, nthCall);
191182
AssertTrailOnResponse(callTrace, AuditTrail, false, nthCall);
192183

@@ -223,7 +214,7 @@ private static string AuditTrailToString(List<Elasticsearch.Net.Audit> auditTrai
223214
public async Task<Auditor> TraceCalls(params ClientCall[] audits)
224215
{
225216
var auditor = this;
226-
foreach (var a in audits.Select((a, i) => new { a, i })) auditor = await auditor.TraceCall(a.a, a.i);
217+
foreach (var a in audits.Select((a, i) => new { a, i })) auditor = await auditor.TraceCall(a.a, a.i).ConfigureAwait(false);
227218
return auditor;
228219
}
229220

@@ -235,11 +226,11 @@ private static void AssertTrailOnResponse(ClientCall callTrace, List<Elasticsear
235226
var actualAuditTrail = auditTrail.Aggregate(new StringBuilder(Environment.NewLine),
236227
(sb, a) => sb.AppendLine($"-> {a}"),
237228
sb => sb.ToString());
238-
239-
callTrace.Select(c => c.Event)
240-
.Should()
241-
.ContainInOrder(auditTrail.Select(a => a.Event),
242-
$"the {nthClientCall} client call's {typeOfTrail} should assert ALL audit trail items{actualAuditTrail}");
229+
230+
var traceEvents =callTrace.Select(c => c.Event).ToList();
231+
var auditEvents = auditTrail.Select(a => a.Event).ToList();
232+
if (!traceEvents.SequenceEqual(auditEvents))
233+
throw new Exception($"the {nthClientCall} client call's {typeOfTrail} should assert ALL audit trail items{actualAuditTrail}");
243234

244235
foreach (var t in auditTrail.Select((a, i) => new { a, i }))
245236
{
@@ -248,13 +239,51 @@ private static void AssertTrailOnResponse(ClientCall callTrace, List<Elasticsear
248239
var nthAuditTrailItem = (i + 1).ToOrdinal();
249240
var because = $"thats the {{0}} specified on the {nthAuditTrailItem} item in the {nthClientCall} client call's {typeOfTrail}";
250241
var c = callTrace[i];
251-
audit.Event.Should().Be(c.Event, string.Format(because, "event"));
252-
if (c.Port.HasValue) audit.Node.Uri.Port.Should().Be(c.Port.Value, string.Format(because, "port"));
242+
if (audit.Event != c.Event)
243+
throw new Exception(string.Format(because, "event"));
244+
if (c.Port.HasValue && audit.Node.Uri.Port != c.Port.Value)
245+
throw new Exception(string.Format(because, "port"));
246+
253247
c.SimpleAssert?.Invoke(audit);
254248
c.AssertWithBecause?.Invoke(string.Format(because, "custom assertion"), audit);
255249
}
256250

257-
callTrace.Count.Should().Be(auditTrail.Count, $"actual auditTrail {actualAuditTrail}");
251+
if (callTrace.Count != auditTrail.Count)
252+
throw new Exception($"callTrace has {callTrace.Count} items. Actual auditTrail {actualAuditTrail}");
258253
}
254+
255+
private static TException TryCall<TException>(Action call, Action<TException> assert) where TException : ElasticsearchClientException
256+
{
257+
TException exception = null;
258+
try
259+
{
260+
call();
261+
}
262+
catch (TException ex)
263+
{
264+
exception = ex;
265+
assert(ex);
266+
}
267+
if (exception is null) throw new Exception("No exception happened while one was expected");
268+
269+
return exception;
270+
}
271+
private static async Task<TException> TryCallAsync<TException>(Func<Task> call, Action<TException> assert) where TException : ElasticsearchClientException
272+
{
273+
TException exception = null;
274+
try
275+
{
276+
await call().ConfigureAwait(false);
277+
}
278+
catch (TException ex)
279+
{
280+
exception = ex;
281+
assert(ex);
282+
}
283+
if (exception is null) throw new Exception("No exception happened while one was expected");
284+
285+
return exception;
286+
}
287+
259288
}
260289
}

0 commit comments

Comments
 (0)