Skip to content

Commit 11820e8

Browse files
committed
[Search] Addressing IndexStatsSummary tests' flakiness
1 parent eba19a8 commit 11820e8

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs

+2-16
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,8 @@ public async Task GetIndexStatsSummary()
142142
Assert.AreEqual(200, response.GetRawResponse().Status);
143143
Assert.IsNotNull(response.Value);
144144
Assert.IsNotNull(response.Value.IndexesStatistics);
145-
Assert.AreEqual(1, response.Value.IndexesStatistics.Count);
146-
Assert.AreEqual(resources.IndexName, response.Value.IndexesStatistics[0].Name);
147-
}
148-
149-
[Test]
150-
[ServiceVersion(Min = SearchClientOptions.ServiceVersion.V2025_03_01_Preview)]
151-
public async Task GetIndexStatsSummaryWithNoIndexes()
152-
{
153-
await using SearchResources resources = SearchResources.CreateWithNoIndexes(this);
154-
155-
SearchIndexClient client = resources.GetIndexClient();
156-
Response<ListIndexStatsSummary> response = await client.GetIndexStatsSummaryAsync();
157-
Assert.AreEqual(200, response.GetRawResponse().Status);
158-
Assert.IsNotNull(response.Value);
159-
Assert.IsNotNull(response.Value.IndexesStatistics);
160-
Assert.AreEqual(0, response.Value.IndexesStatistics.Count);
145+
Assert.GreaterOrEqual(response.Value.IndexesStatistics.Count, 1);
146+
Assert.True(response.Value.IndexesStatistics.Any(summary => summary.Name == resources.IndexName));
161147
}
162148

163149
[Test]

sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public static SearchResources CreateWithNoIndexes(SearchTestBase fixture)
175175
/// <returns>A new TestResources context.</returns>
176176
public static async Task<SearchResources> CreateWithEmptyIndexAsync<T>(SearchTestBase fixture, bool isSample = false)
177177
{
178+
// TODO: consider setting up RequiresCleanup so the index is deleted at the end of the test run.
178179
var resources = new SearchResources(fixture);
179180
await resources.CreateSearchServiceAndIndexAsync(isSample, name =>
180181
new SearchIndex(name)
@@ -195,6 +196,7 @@ await resources.CreateSearchServiceAndIndexAsync(isSample, name =>
195196
/// <returns>A new TestResources context.</returns>
196197
public static async Task<SearchResources> CreateWithEmptyHotelsIndexAsync(SearchTestBase fixture, bool isSample = false)
197198
{
199+
// TODO: consider setting up RequiresCleanup so the index is deleted at the end of the test run.
198200
var resources = new SearchResources(fixture);
199201
await resources.CreateSearchServiceAndIndexAsync(isSample);
200202
return resources;
@@ -211,6 +213,7 @@ public static async Task<SearchResources> CreateWithEmptyHotelsIndexAsync(Search
211213
/// <returns>A new TestResources context.</returns>
212214
public static async Task<SearchResources> CreateWithHotelsIndexAsync(SearchTestBase fixture, bool isSample = false)
213215
{
216+
// TODO: consider setting up RequiresCleanup so the index is deleted at the end of the test run.
214217
var resources = new SearchResources(fixture);
215218
await resources.CreateSearchServiceIndexAndDocumentsAsync(isSample);
216219
return resources;
@@ -230,6 +233,7 @@ public static async Task<SearchResources> CreateWithHotelsIndexAsync(SearchTestB
230233
/// <returns>A new <see cref="SearchResources"/> context.</returns>
231234
public static async Task<SearchResources> CreateWithBlobStorageAsync(SearchTestBase fixture, bool populate = false, bool isSample = false)
232235
{
236+
// TODO: consider setting up RequiresCleanup so the index is deleted at the end of the test run.
233237
var resources = new SearchResources(fixture);
234238
await resources.CreateHotelsBlobContainerAsync(populate, isSample);
235239
return resources;
@@ -249,6 +253,7 @@ public static async Task<SearchResources> CreateWithBlobStorageAsync(SearchTestB
249253
/// <returns>A new <see cref="SearchResources"/> context.</returns>
250254
public static async Task<SearchResources> CreateWithBlobStorageAndIndexAsync(SearchTestBase fixture, bool populate = false, bool isSample = false)
251255
{
256+
// TODO: consider setting up RequiresCleanup so the index is deleted at the end of the test run.
252257
var resources = new SearchResources(fixture);
253258

254259
// Keep them ordered or records may not match seeded random names.
@@ -271,6 +276,8 @@ public static async Task<SearchResources> CreateWithBlobStorageAndIndexAsync(Sea
271276
/// <returns>The shared TestResources context.</returns>
272277
public static async Task<SearchResources> GetSharedHotelsIndexAsync(SearchTestBase fixture, bool isSample = false)
273278
{
279+
// TODO: consider whether we should delete the index at the end of the test run here.
280+
// SharedSearchResources seems to purposely cache the index.
274281
await SharedSearchResources.EnsureInitialized(async () => await CreateWithHotelsIndexAsync(fixture, isSample), isSample);
275282

276283
// Clone it for the current fixture (note that setting these values

0 commit comments

Comments
 (0)