From 2f8581011877dc5d4f213d15cbe20048064a361d Mon Sep 17 00:00:00 2001 From: Davyd McColl Date: Tue, 14 Nov 2023 16:03:44 +0200 Subject: [PATCH] :alembic: put a retry around a time-sensitive test --- .../TestTempDbMySqlConnector.cs | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/source/TempDb/PeanutButter.TempDb.MySql.Connector.Tests/TestTempDbMySqlConnector.cs b/source/TempDb/PeanutButter.TempDb.MySql.Connector.Tests/TestTempDbMySqlConnector.cs index ef9100dc87..b606e3b90c 100644 --- a/source/TempDb/PeanutButter.TempDb.MySql.Connector.Tests/TestTempDbMySqlConnector.cs +++ b/source/TempDb/PeanutButter.TempDb.MySql.Connector.Tests/TestTempDbMySqlConnector.cs @@ -377,37 +377,45 @@ TimeSpan maxWait public void ConnectionUseShouldExtendLifetime() { // Arrange - var disposed = new ConcurrentQueue(); - 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(); + 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() + .With.Message.Containing("not running"); + } + + // Assert + Expect(disposed.ToArray()) + .To.Equal( + new[] { - using var conn = db.OpenConnection(); + true } - ).To.Throw() - .With.Message.Containing("not running"); - } - - // Assert - Expect(disposed.ToArray()) - .To.Equal(new[] { true }); + ); + }); } [Test]