Skip to content

Commit

Permalink
⚗️ put a retry around a time-sensitive test
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffynuts committed Nov 14, 2023
1 parent a787028 commit 2f85810
Showing 1 changed file with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,37 +377,45 @@ TimeSpan maxWait
public void ConnectionUseShouldExtendLifetime()
{
// Arrange
var disposed = new ConcurrentQueue<bool>();
using (var db = Create(inactivityTimeout: TimeSpan.FromSeconds(1)))
Retry.Max(3).Times(() =>
{
db.Disposed += (o, e) => disposed.Enqueue(true);
// Act
for (var i = 0; i < 5; i++)
var disposed = new ConcurrentQueue<bool>();
using (var db = Create(inactivityTimeout: TimeSpan.FromSeconds(1)))
{
Expect(
() =>
{
using var conn = db.OpenConnection();
Thread.Sleep(500);
}
).Not.To.Throw();
}
db.Disposed += (o, e) => disposed.Enqueue(true);
// Act
for (var i = 0; i < 5; i++)
{
Expect(
() =>
{
using var conn = db.OpenConnection();
Thread.Sleep(500);
}
).Not.To.Throw();
}

WaitFor(() => disposed.Any(), 10000);
WaitFor(() => disposed.Any(), 10000);


Expect(
() =>
Expect(
() =>
{
using var conn = db.OpenConnection();
}
).To.Throw<InvalidOperationException>()
.With.Message.Containing("not running");
}

// Assert
Expect(disposed.ToArray())
.To.Equal(
new[]
{
using var conn = db.OpenConnection();
true
}
).To.Throw<InvalidOperationException>()
.With.Message.Containing("not running");
}

// Assert
Expect(disposed.ToArray())
.To.Equal(new[] { true });
);
});
}

[Test]
Expand Down

0 comments on commit 2f85810

Please sign in to comment.