Skip to content

Commit

Permalink
Use event listener locally within the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohit-Chakraborty committed Jun 22, 2021
1 parent dedd1e1 commit 0ee14a9
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions sdk/search/Azure.Search.Documents/tests/Batching/BatchingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,13 @@

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;

public BatchingTests(bool async, SearchClientOptions.ServiceVersion serviceVersion)
: base(async, serviceVersion, null /* RecordedTestMode.Record /* to re-record */)
{
}

[SetUp]
public void Setup()
{
_listener = new TestEventListener();
_listener.EnableEvents(AzureSearchDocumentsEventSource.Instance, EventLevel.Verbose);
}

[TearDown]
public void TearDown()
{
_listener.Dispose();
}

#region Utilities
private const int BatchSize = SearchIndexingBufferedSenderOptions<object>.DefaultInitialBatchActionCount;
private readonly TimeSpan EventDelay = TimeSpan.FromMilliseconds(250);
Expand Down Expand Up @@ -1066,10 +1049,13 @@ public async Task Behavior_Split()

client.SplitNextBatch = true;

using TestEventListener listener = new();
listener.EnableEvents(AzureSearchDocumentsEventSource.Instance, EventLevel.Verbose);

await indexer.UploadDocumentsAsync(data);
await indexer.FlushAsync();

List<EventWrittenEventArgs> eventData = _listener.EventData.ToList();
List<EventWrittenEventArgs> eventData = listener.EventData.ToList();

Assert.AreEqual(10, eventData.Count);
Assert.AreEqual("PendingQueueResized", eventData[0].EventName); // 1. All events are pushed into the pending queue.
Expand Down

0 comments on commit 0ee14a9

Please sign in to comment.