Skip to content

Commit 8b71b98

Browse files
committed
Merge pull request #2028 from elastic/fix/task-cancel-test-flakeyness
The task cancel API test was a bit flakey,
2 parents 694b366 + 7ad57b4 commit 8b71b98

File tree

30 files changed

+137
-96
lines changed

30 files changed

+137
-96
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<ICatResponse<CatRe
1717

1818
public CatRepositoriesApiTests(IndexingCluster 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<ICatResponse<CatSnaps
1919

2020
public CatSnapshotsApiTests(IndexingCluster 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

src/Tests/Cluster/TaskManagement/TasksCancel/TasksCancelApiTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,31 @@
1010

1111
namespace Tests.Cluster.TaskManagement.TasksCancel
1212
{
13-
// TODO Unit tests will fail in mixed mode because SetupTaskIds isn't setup
1413
[Collection(IntegrationContext.OwnIndex)]
1514
public class TasksCancelApiTests : ApiIntegrationTestBase<ITasksCancelResponse, ITasksCancelRequest, TasksCancelDescriptor, TasksCancelRequest>
1615
{
17-
public class Test
16+
private TaskId TaskId => this.RanIntegrationSetup ? this.ExtendedValue<TaskId>("taskId") : "foo:1";
17+
18+
private class Test
1819
{
1920
public long Id { get; set; }
2021
public string Flag { get; set; }
2122
}
2223

2324
public TasksCancelApiTests(OwnIndexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
2425

25-
protected IDictionary<string, TaskId> SetupTaskIds { get; } = new Dictionary<string, TaskId>();
26-
27-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
26+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
2827
{
2928
foreach (var index in values.Values)
3029
{
3130
client.IndexMany(Enumerable.Range(0, 10000).Select(i => new Test { Id = i + 1, Flag = "bar" }), index);
3231
client.Refresh(index);
3332
}
34-
foreach (var index in values.Values)
33+
foreach (var view in values.Views)
3534
{
35+
values.CurrentView = view;
36+
var index = values.Value;
37+
3638
var reindex = client.ReindexOnServer(r => r
3739
.Source(s => s.Index(index))
3840
.Destination(s => s.Index($"{index}-clone"))
@@ -42,7 +44,7 @@ protected override void BeforeAllCalls(IElasticClient client, IDictionary<Client
4244
var taskId = reindex.Task;
4345
var taskInfo = client.TasksList(new TasksListRequest(taskId));
4446
taskInfo.IsValid.Should().BeTrue();
45-
this.SetupTaskIds[index] = taskId;
47+
values.ExtendedValue("taskId", taskId);
4648
}
4749
}
4850
protected override LazyResponses ClientUsage() => Calls(
@@ -58,20 +60,18 @@ protected override LazyResponses ClientUsage() => Calls(
5860
protected override string UrlPath => $"/_tasks/{Uri.EscapeDataString(this.TaskId.ToString())}/_cancel";
5961
protected override bool SupportsDeserialization => false;
6062

61-
private TaskId TaskId => TestClient.Configuration.RunIntegrationTests ? this.SetupTaskIds[CallIsolatedValue] : "foo:1";
6263

6364
protected override Func<TasksCancelDescriptor, ITasksCancelRequest> Fluent => d => d
6465
.TaskId(this.TaskId);
6566

6667
protected override TasksCancelRequest Initializer => new TasksCancelRequest(this.TaskId);
6768

68-
// TODO this test is flaky, sometimes SetupTaskIds is empty
6969
protected override void ExpectResponse(ITasksCancelResponse response)
7070
{
7171
response.NodeFailures.Should().BeNullOrEmpty();
7272
response.Nodes.Should().NotBeEmpty();
7373
var tasks = response.Nodes.First().Value.Tasks;
74-
tasks.Should().NotBeEmpty().And.ContainKey(this.SetupTaskIds[CallIsolatedValue]);
74+
tasks.Should().NotBeEmpty().And.ContainKey(this.TaskId);
7575
}
7676
}
7777
}

src/Tests/Document/Multiple/DeleteByQuery/DeleteByQueryApiTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class DeleteByQueryApiTests : ApiIntegrationTestBase<IDeleteByQueryRespon
1717
{
1818
public DeleteByQueryApiTests(OwnIndexCluster 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
foreach (var index in values.Values)
2323
{
@@ -44,7 +44,7 @@ protected override LazyResponses ClientUsage() => Calls(
4444

4545
protected override bool SupportsDeserialization => false;
4646

47-
protected override object ExpectJson { get; } = new
47+
protected override object ExpectJson { get; } = new
4848
{
4949
query = new
5050
{
@@ -66,7 +66,7 @@ protected override LazyResponses ClientUsage() => Calls(
6666
.Values(Project.Projects.First().Name, "x")
6767
)
6868
);
69-
69+
7070
protected override DeleteByQueryRequest Initializer => new DeleteByQueryRequest(this.Indices)
7171
{
7272
IgnoreUnavailable = true,

src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Test
2323

2424
public ReindexOnServerApiTests(OwnIndexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
2525

26-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
26+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
2727
{
2828
foreach (var index in values.Values)
2929
{

src/Tests/Document/Multiple/UpdateByQuery/UpdateByQueryApiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Test
2323

2424
public UpdateByQueryApiTests(OwnIndexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
2525

26-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
26+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
2727
{
2828
foreach (var index in values.Values)
2929
{
@@ -131,7 +131,7 @@ public class UpdateByQueryWithFailuresApiTests : UpdateByQueryApiTests
131131
{
132132
public UpdateByQueryWithFailuresApiTests(OwnIndexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
133133

134-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
134+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
135135
{
136136
foreach (var index in values.Values)
137137
{

src/Tests/Document/Single/Delete/DeleteApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DeleteApiTests : ApiIntegrationTestBase<IDeleteResponse, IDeleteReq
1414
{
1515
public DeleteApiTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1616

17-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
17+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
1818
{
1919
foreach (var id in values.Values)
2020
this.Client.Index(Project.Instance, i=>i.Id(id));

src/Tests/Document/Single/Exists/DocumentExistsApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DocumentExistsApiTests : ApiIntegrationTestBase<IExistsResponse, ID
1414
{
1515
public DocumentExistsApiTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1616

17-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
17+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
1818
{
1919
foreach (var id in values.Values)
2020
this.Client.Index(Project.Instance, i=>i.Id(id));

src/Tests/Document/Single/Update/UpdateApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class UpdateApiTests : ApiIntegrationTestBase<IUpdateResponse<Project>, I
1414
{
1515
public UpdateApiTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1616

17-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
17+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
1818
{
1919
foreach (var id in values.Values)
2020
this.Client.Index(Project.Instance, i=>i.Id(id));

src/Tests/Document/Single/Update/UpdateWithSourceApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class UpdateWithSourceApiTests : ApiIntegrationTestBase<IUpdateResponse<P
1818
{
1919
public UpdateWithSourceApiTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
2020

21-
protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values)
21+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
2222
{
2323
foreach (var id in values.Values)
2424
this.Client.Index(Project.Instance, i=>i.Id(id));

0 commit comments

Comments
 (0)