diff --git a/sdk/search/Azure.Search.Documents/tests/Samples/Sample01_HelloWorld.cs b/sdk/search/Azure.Search.Documents/tests/Samples/Sample01_HelloWorld.cs index d5393f93f6f01..f003498fafe8b 100644 --- a/sdk/search/Azure.Search.Documents/tests/Samples/Sample01_HelloWorld.cs +++ b/sdk/search/Azure.Search.Documents/tests/Samples/Sample01_HelloWorld.cs @@ -348,15 +348,7 @@ public async Task CreateIndexerAsync() cleanUpTasks.Push(() => indexerClient.DeleteIndexerAsync(indexerName)); // Wait till the indexer is done. - try - { - await WaitForIndexingAsync(indexerClient, indexerName); - } - catch (TaskCanceledException) - { - // TODO: Remove this when we figure out a more correlative way of checking status. - Assert.Inconclusive("Timed out while waiting for the indexer to complete"); - } + await WaitForIndexingAsync(indexerClient, indexerName); #region Snippet:Azure_Search_Tests_Samples_CreateIndexerAsync_Query // Get a SearchClient from the SearchIndexClient to share its pipeline. diff --git a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs index 0985a3d984474..a00f57979686f 100644 --- a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs +++ b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchTestBase.cs @@ -199,11 +199,20 @@ protected async Task WaitForIndexingAsync( while (true) { - await DelayAsync(delay, cancellationToken: cts.Token); + SearchIndexerStatus status = null; + try + { + await DelayAsync(delay, cancellationToken: cts.Token); - SearchIndexerStatus status = await client.GetIndexerStatusAsync( - indexerName, - cancellationToken: cts.Token); + status = await client.GetIndexerStatusAsync( + indexerName, + cancellationToken: cts.Token); + } + catch (TaskCanceledException) + { + // TODO: Remove this when we figure out a more correlative way of checking status. + Assert.Inconclusive("Timed out while waiting for the indexer to complete"); + } if (status.Status == IndexerStatus.Running) {