Skip to content

Commit 739ff8f

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 9745cef commit 739ff8f

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
@@ -23,6 +23,12 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
2323
PutFilter(client, callUniqueValue.Value);
2424
}
2525

26+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
27+
{
28+
foreach (var callUniqueValue in values)
29+
DeleteFilter(client, callUniqueValue.Value);
30+
}
31+
2632
protected override bool ExpectIsValid => true;
2733

2834
protected override object ExpectJson => null;
@@ -76,6 +82,13 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
7682
}
7783
}
7884

85+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
86+
{
87+
foreach (var callUniqueValue in values)
88+
for (var i = 0; i < 3; i++)
89+
DeleteFilter(client, callUniqueValue.Value + "_" + (i + 1));
90+
}
91+
7992
protected override bool ExpectIsValid => true;
8093

8194
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
@@ -51,6 +51,16 @@ protected IPutFilterResponse PutFilter(IElasticClient client, string filterId)
5151
return putFilterResponse;
5252
}
5353

54+
protected IDeleteFilterResponse DeleteFilter(IElasticClient client, string filterId)
55+
{
56+
var deleteFilterResponse = client.DeleteFilter(filterId);
57+
58+
if (!deleteFilterResponse.IsValid)
59+
throw new Exception($"Problem deleting filter {filterId} for integration test: {deleteFilterResponse.DebugInformation}");
60+
61+
return deleteFilterResponse;
62+
}
63+
5464
protected IPutCalendarResponse PutCalendar(IElasticClient client, string calendarId)
5565
{
5666
var putCalendarResponse = client.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
@@ -15,6 +15,12 @@ public class PutFilterApiTests : MachineLearningIntegrationTestBase<IPutFilterRe
1515
{
1616
public PutFilterApiTests(MachineLearningCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1717

18+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
19+
{
20+
foreach (var callUniqueValue in values)
21+
DeleteFilter(client, callUniqueValue.Value);
22+
}
23+
1824
protected override bool ExpectIsValid => true;
1925

2026
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
@@ -22,6 +22,12 @@ protected override void IntegrationSetup(IElasticClient client, CallUniqueValues
2222
PutFilter(client, callUniqueValue.Value);
2323
}
2424

25+
protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
26+
{
27+
foreach (var callUniqueValue in values)
28+
DeleteFilter(client, callUniqueValue.Value);
29+
}
30+
2531
protected override bool ExpectIsValid => true;
2632

2733
protected override object ExpectJson => new

0 commit comments

Comments
 (0)