Skip to content

Commit 5c36f2d

Browse files
committed
Ensure filters created are deleted (#4047)
This commit updates ML filter integration tests to ensure that filters created as part of a test are deleted.
1 parent f9540be commit 5c36f2d

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/Tests/Tests/XPack/MachineLearning/GetFilters/GetFiltersApiTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
2020
PutFilter(client, callUniqueValue.Value);
2121
}
2222

23+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
24+
{
25+
foreach (var callUniqueValue in values)
26+
DeleteFilter(client, callUniqueValue.Value);
27+
}
28+
2329
protected override bool ExpectIsValid => true;
2430

2531
protected override object ExpectJson => null;
@@ -71,6 +77,13 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
7177
PutFilter(client, callUniqueValue.Value + "_" + (i + 1));
7278
}
7379

80+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
81+
{
82+
foreach (var callUniqueValue in values)
83+
for (var i = 0; i < 3; i++)
84+
DeleteFilter(client, callUniqueValue.Value + "_" + (i + 1));
85+
}
86+
7487
protected override bool ExpectIsValid => true;
7588

7689
protected override object ExpectJson => null;

src/Tests/Tests/XPack/MachineLearning/MachineLearningIntegrationTestBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ protected PutFilterResponse PutFilter(IElasticClient client, string filterId)
5050
return putFilterResponse;
5151
}
5252

53+
protected DeleteFilterResponse DeleteFilter(IElasticClient client, string filterId)
54+
{
55+
var deleteFilterResponse = client.MachineLearning.DeleteFilter(filterId);
56+
57+
if (!deleteFilterResponse.IsValid)
58+
throw new Exception($"Problem deleting filter {filterId} for integration test: {deleteFilterResponse.DebugInformation}");
59+
60+
return deleteFilterResponse;
61+
}
62+
5363
protected PutCalendarResponse PutCalendar(IElasticClient client, string calendarId)
5464
{
5565
var putCalendarResponse = client.MachineLearning.PutCalendar(calendarId, f => f

src/Tests/Tests/XPack/MachineLearning/PutFilter/PutFilterApiTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public class PutFilterApiTests : MachineLearningIntegrationTestBase<PutFilterRes
1313
{
1414
public PutFilterApiTests(MachineLearningCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1515

16+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
17+
{
18+
foreach (var callUniqueValue in values)
19+
DeleteFilter(client, callUniqueValue.Value);
20+
}
21+
1622
protected override bool ExpectIsValid => true;
1723

1824
protected override object ExpectJson => new

src/Tests/Tests/XPack/MachineLearning/UpdateFilter/UpdateFilterApiTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
2020
PutFilter(client, callUniqueValue.Value);
2121
}
2222

23+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
24+
{
25+
foreach (var callUniqueValue in values)
26+
DeleteFilter(client, callUniqueValue.Value);
27+
}
28+
2329
protected override bool ExpectIsValid => true;
2430

2531
protected override object ExpectJson => new

0 commit comments

Comments
 (0)