Skip to content

Commit

Permalink
[C#] Fix timing issue in testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed May 13, 2021
1 parent 79eaa00 commit 36de988
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cs/test/FasterLogRecoverReadOnlyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class FasterLogRecoverReadOnlyTests
string path;
string deviceName;
CancellationTokenSource cts;
SemaphoreSlim done;

[SetUp]
public void Setup()
Expand All @@ -31,6 +32,7 @@ public void Setup()
if (Directory.Exists(path))
TestUtils.DeleteDirectory(path);
cts = new CancellationTokenSource();
done = new SemaphoreSlim(0);
}

[TearDown]
Expand Down Expand Up @@ -61,7 +63,8 @@ private async Task ProducerAsync(FasterLog log, CancellationTokenSource cts)
log.RefreshUncommitted();
await Task.Delay(TimeSpan.FromMilliseconds(ProducerPauseMs));
}
await Task.Delay(TimeSpan.FromMilliseconds(CommitPeriodMs * 4));
// Ensure the reader had time to see all data
await done.WaitAsync();
cts.Cancel();
}

Expand Down Expand Up @@ -99,6 +102,8 @@ private async Task ReadOnlyConsumerAsync(string deviceName, CancellationToken ca
Assert.AreEqual(prevValue + 1, value);
prevValue = value;
iter.CompleteUntil(nextAddress);
if (prevValue == NumElements - 1)
done.Release();
}
} catch (OperationCanceledException) { }
Assert.AreEqual(NumElements - 1, prevValue);
Expand Down

0 comments on commit 36de988

Please sign in to comment.