Skip to content

Commit

Permalink
adjust futures test tolerances
Browse files Browse the repository at this point in the history
Signed-off-by: Chloe McKnight <cmcknight@bluebeam.com>
  • Loading branch information
cmcknight-bb committed Jan 15, 2025
1 parent 3cb3c4d commit 3405372
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dotnet-tests/UniffiCS.BindingTests/TestFutures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ static async Task<long> MeasureTimeMillis(Func<Task> callback) {

static async Task ReturnsImmediately(Func<Task> callback) {
var time = await MeasureTimeMillis(callback);
AssertApproximateTime(0, 4, time);
AssertApproximateTime(0, 20, time);
}

static async Task ReturnsIn(long expected, Func<Task> callback) {
await ReturnsIn(expected, 50, callback);
}

static async Task ReturnsIn(long expected, long tolerance, Func<Task> callback) {
var time = await MeasureTimeMillis(callback);
AssertApproximateTime(expected, 50, time);
AssertApproximateTime(expected, tolerance, time);
}

static void AssertApproximateTime(long expected, long tolerance, long actual) {
Expand Down Expand Up @@ -116,7 +120,7 @@ public async void TestAsyncFallibleFunctions() {
await ReturnsImmediately(async () => {
await FuturesMethods.FallibleMe(false);
await Assert.ThrowsAsync<MyException.Foo>(() => FuturesMethods.FallibleMe(true));
using (var megaphone = FuturesMethods.NewMegaphone()) {
using (var megaphone = FuturesMethods.NewMegaphone()) {
Assert.Equal(42, await megaphone.FallibleMe(false));
await Assert.ThrowsAsync<MyException.Foo>(() => megaphone.FallibleMe(true));
}
Expand Down Expand Up @@ -144,7 +148,7 @@ await ReturnsImmediately(async () => {

[Fact]
public async void TestBrokenSleep() {
await ReturnsIn(500, async () => {
await ReturnsIn(500, 100, async () => {
// calls the waker twice immediately
await FuturesMethods.BrokenSleep(100, 0);
// wait for possible failure
Expand Down

0 comments on commit 3405372

Please sign in to comment.