Skip to content

Commit

Permalink
Manually synchronize the test and add more print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
nand4011 committed Sep 1, 2023
1 parent 117257e commit fc66489
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/Integration/Momento.Sdk.Tests/TopicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public TopicTest(CacheClientFixture cacheFixture, TopicClientFixture topicFixtur
[Fact(Timeout = 5000)]
public async Task PublishAndSubscribe_ByteArray_Succeeds()
{
testOutputHelper.WriteLine("starting binary publish and subscribe test");
await Console.Error.WriteLineAsync("starting binary publish and subscribe test");
const string topicName = "topic_bytes";
var valuesToSend = new List<byte[]>
{
Expand All @@ -106,9 +106,13 @@ public async Task PublishAndSubscribe_ByteArray_Succeeds()
$"Unexpected response: {subscribeResponse}");
var subscription = ((TopicSubscribeResponse.Subscription)subscribeResponse).WithCancellation(cts.Token);

await Console.Error.WriteLineAsync("subscription created");
var taskCompletionSourceBool = new TaskCompletionSource<bool>();
var testTask = Task.Run(async () =>
{
var messageCount = 0;
// semaphore.
taskCompletionSourceBool.SetResult(true);
await foreach (var message in subscription)
{
Assert.NotNull(message);
Expand All @@ -126,14 +130,16 @@ public async Task PublishAndSubscribe_ByteArray_Succeeds()
return messageCount;
}, cts.Token);

await Task.Delay(1000);
await Console.Error.WriteLineAsync("enumerator task started");
await taskCompletionSourceBool.Task;

foreach (var value in valuesToSend)
{
var publishResponse = await topicClient.PublishAsync(cacheName, topicName, value);
Assert.True(publishResponse is TopicPublishResponse.Success, $"Unexpected response: {publishResponse}");
await Task.Delay(100);
}
await Console.Error.WriteLineAsync("messages sent");

Assert.Equal(valuesToSend.Count, await testTask);
}
Expand Down

0 comments on commit fc66489

Please sign in to comment.