Skip to content

Commit 15a02f9

Browse files
committed
The task cancel API test was a bit flakey,
It was setting additional values in the integration setup on the class itself but this setup is run once for possibly multiple classes e.g EndpointUsage x; new TestClass(x).Test1(); new TestClass(x).Test2(); new TestClass(x).Test3(); new TestClass(x).Test4(); new TestClass(x).Test5(); integration setup is an override per TestClass but only one of them will be called per instance of `x`. So if the callback defines setting variables on the `TestClass` instance using `this` other TestClass instances won't see this. This PR makes CallIsolatedValues a class of its own that allows you to register extended values that can be shared amongst all TestClass instances.
1 parent a8ab6ec commit 15a02f9

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

src/Tests/Cat/CatRepositories/CatRepositoriesApiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class CatRepositoriesApiTests : ApiIntegrationTestBase<IntrusiveOperation
1717

1818
public CatRepositoriesApiTests(IntrusiveOperationCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1919

20-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
20+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
2121
{
2222
if (!TestClient.Configuration.RunIntegrationTests) return;
23-
var repositoryLocation = Path.Combine(this._cluster.Node.RepositoryPath, RandomString());
23+
var repositoryLocation = Path.Combine(this.Cluster.Node.RepositoryPath, RandomString());
2424

2525
var create = this.Client.CreateRepository(RepositoryName, cr => cr
2626
.FileSystem(fs => fs

src/Tests/Cat/CatSnapshots/CatSnapshotsApiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class CatSnapshotsApiTests : ApiIntegrationTestBase<IntrusiveOperationClu
1919

2020
public CatSnapshotsApiTests(IntrusiveOperationCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
2121

22-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
22+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
2323
{
2424
if (!TestClient.Configuration.RunIntegrationTests) return;
25-
var repositoryLocation = Path.Combine(this._cluster.Node.RepositoryPath, RandomString());
25+
var repositoryLocation = Path.Combine(this.Cluster.Node.RepositoryPath, RandomString());
2626

2727
var create = this.Client.CreateRepository(RepositoryName, cr => cr
2828
.FileSystem(fs => fs
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Tests.Framework.Integration
5+
{
6+
public class CallUniqueValues : Dictionary<ClientMethod, string>
7+
{
8+
private string UniqueValue => "nest-" + Guid.NewGuid().ToString("N").Substring(0, 8);
9+
10+
private IDictionary<ClientMethod, IDictionary<string, object>> ExtendedValues { get; }
11+
= new Dictionary<ClientMethod, IDictionary<string, object>>();
12+
13+
public ClientMethod CurrentView { get; set; } = ClientMethod.Fluent;
14+
public ClientMethod[] Views { get; } = new[] { ClientMethod.Fluent, ClientMethod.FluentAsync, ClientMethod.Initializer, ClientMethod.InitializerAsync };
15+
16+
public string Value => this[CurrentView];
17+
public T ExtendedValue<T>(string key) where T : class => this.ExtendedValues[CurrentView][key] as T;
18+
public void ExtendedValue<T>(string key, T value) where T : class => this.ExtendedValues[CurrentView][key] = value;
19+
20+
public CallUniqueValues()
21+
{
22+
this.Add(ClientMethod.Fluent, this.UniqueValue);
23+
this.Add(ClientMethod.FluentAsync, this.UniqueValue);
24+
this.Add(ClientMethod.Initializer, this.UniqueValue);
25+
this.Add(ClientMethod.InitializerAsync, this.UniqueValue);
26+
27+
this.ExtendedValues.Add(ClientMethod.Fluent, new Dictionary<string, object>());
28+
this.ExtendedValues.Add(ClientMethod.FluentAsync, new Dictionary<string, object>());
29+
this.ExtendedValues.Add(ClientMethod.Initializer, new Dictionary<string, object>());
30+
this.ExtendedValues.Add(ClientMethod.InitializerAsync, new Dictionary<string, object>());
31+
}
32+
}
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Tests.Framework.Integration
2+
{
3+
public enum ClientMethod
4+
{
5+
Fluent,
6+
FluentAsync,
7+
Initializer,
8+
InitializerAsync
9+
}
10+
}

src/Tests/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: m
2+
mode: u
33
# the elasticsearch version that should be started
44
# Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype
55
elasticsearch_version: latest

0 commit comments

Comments
 (0)