Skip to content

Commit

Permalink
[Search] Avoid storm of error events being logged when running test (#…
Browse files Browse the repository at this point in the history
…21988)

* Mark EventListener using tests as non-parallelizable

* Adjust test that throws exceptions from indexing action handlers
Reduce number of documents used in the test so that EventSource does not log a very large number of events.

* Do not create proxies from proxies

* Fix more tests to avoid event exceptions

* Use GetOriginal() helper method when creating proxies
  • Loading branch information
Mohit-Chakraborty authored Jul 2, 2021
1 parent b89c1d4 commit 3f7cfd0
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 22,629 deletions.
19 changes: 10 additions & 9 deletions sdk/search/Azure.Search.Documents/tests/Batching/BatchingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace Azure.Search.Documents.Tests
{
// Avoid running these tests in parallel with anything else that's sharing the event source
[NonParallelizable]
public class BatchingTests : SearchTestBase
{
private TestEventListener _listener;
Expand Down Expand Up @@ -452,11 +454,12 @@ public async Task KeyFieldAccessor_FieldBuilder()
{
await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync<SimpleDocument>(this);
SearchClient client = resources.GetSearchClient();

LessSimpleDocument[] data = LessSimpleDocument.GetDocuments(10);

await using SearchIndexingBufferedSender<LessSimpleDocument> indexer =
new SearchIndexingBufferedSender<LessSimpleDocument>(client);
await using SearchIndexingBufferedSender<LessSimpleDocument> indexer = new(GetOriginal(client));
AssertNoFailures(indexer);

await indexer.UploadDocumentsAsync(data);
await indexer.FlushAsync();
await WaitForDocumentCountAsync(resources.GetSearchClient(), data.Length);
Expand Down Expand Up @@ -1009,7 +1012,7 @@ public async Task Notifications_ExceptionsGetSwallowed()
{
await using SearchResources resources = await SearchResources.CreateWithEmptyIndexAsync<SimpleDocument>(this);
BatchingSearchClient client = GetBatchingSearchClient(resources);
SimpleDocument[] data = SimpleDocument.GetDocuments(BatchSize);
SimpleDocument[] data = SimpleDocument.GetDocuments(2);

await using SearchIndexingBufferedSender<SimpleDocument> indexer =
client.CreateIndexingBufferedSender(
Expand Down Expand Up @@ -1149,7 +1152,6 @@ public async Task Behavior_SplitBatchByDocumentKey()
InitialBatchActionCount = numberOfDocuments + 1,
});

// Throw from every handler
int sent = 0, completed = 0;
indexer.ActionSent += e =>
{
Expand All @@ -1159,7 +1161,7 @@ public async Task Behavior_SplitBatchByDocumentKey()
// So, 3 documents will be sent before any are submitted, but 3 submissions will be made before the last 2 are sent
Assert.AreEqual((sent <= 3) ? 0 : 3, completed);

throw new InvalidOperationException("ActionSentAsync: Should not be seen!");
return Task.CompletedTask;
};

indexer.ActionCompleted += e =>
Expand All @@ -1170,7 +1172,7 @@ public async Task Behavior_SplitBatchByDocumentKey()
// So, 3 documents will be submitted after 3 are sent, and the last 2 submissions will be made after all 5 are sent
Assert.AreEqual((completed <= 3) ? 3 : 5, sent);

throw new InvalidOperationException("ActionCompletedAsync: Should not be seen!");
return Task.CompletedTask;
};

AssertNoFailures(indexer);
Expand Down Expand Up @@ -1209,7 +1211,6 @@ public async Task Behavior_SplitBatchByDocumentKeyIgnoreCaseDifferences()
InitialBatchActionCount = numberOfDocuments + 1,
});

// Throw from every handler
int sent = 0, completed = 0;
indexer.ActionSent += e =>
{
Expand All @@ -1218,7 +1219,7 @@ public async Task Behavior_SplitBatchByDocumentKeyIgnoreCaseDifferences()
// Batch will not be split. So, no document will be submitted before all are sent.
Assert.AreEqual(0, completed);

throw new InvalidOperationException("ActionSentAsync: Should not be seen!");
return Task.CompletedTask;
};

indexer.ActionCompleted += e =>
Expand All @@ -1228,7 +1229,7 @@ public async Task Behavior_SplitBatchByDocumentKeyIgnoreCaseDifferences()
// Batch will not be split. So, all documents will be sent before any are submitted.
Assert.AreEqual(5, sent);

throw new InvalidOperationException("ActionCompletedAsync: Should not be seen!");
return Task.CompletedTask;
};

AssertNoFailures(indexer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public async Task BufferedSender()

// Simple
{
searchClient = GetOriginal(searchClient);

#region Snippet:Azure_Search_Documents_Tests_Samples_Sample05_IndexingDocuments_BufferedSender1
await using SearchIndexingBufferedSender<Product> indexer =
new SearchIndexingBufferedSender<Product>(searchClient);
Expand Down
Loading

0 comments on commit 3f7cfd0

Please sign in to comment.