diff --git a/projects/Test/Integration/TestAsyncConsumer.cs b/projects/Test/Integration/TestAsyncConsumer.cs index 2b658de6c..160fdd309 100644 --- a/projects/Test/Integration/TestAsyncConsumer.cs +++ b/projects/Test/Integration/TestAsyncConsumer.cs @@ -71,6 +71,7 @@ public async Task TestBasicRoundtripConcurrent() var consumer = new AsyncEventingBasicConsumer(_channel); + var consumerRegisteredTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var publish1SyncSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var publish2SyncSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -105,6 +106,20 @@ public async Task TestBasicRoundtripConcurrent() return Task.CompletedTask; }; + consumer.RegisteredAsync += (object sender, ConsumerEventArgs ea) => + { + if (ReferenceEquals(consumer, sender)) + { + consumerRegisteredTcs.SetResult(true); + } + else + { + var ex = Xunit.Sdk.EqualException.ForMismatchedValues(consumer, sender); + consumerRegisteredTcs.SetException(ex); + } + return Task.CompletedTask; + }; + consumer.ReceivedAsync += (o, a) => { if (ByteArraysEqual(a.Body.Span, body1)) @@ -126,6 +141,7 @@ public async Task TestBasicRoundtripConcurrent() }; await _channel.BasicConsumeAsync(q.QueueName, true, string.Empty, false, false, null, consumer); + await consumerRegisteredTcs.Task.WaitAsync(WaitSpan); try {