Skip to content

Commit faac9ba

Browse files
committed
CSHARP-1707: Set SpinWait timeouts to a larger value to reduce test failures on slow machines.
1 parent 8e8af32 commit faac9ba

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

tests/MongoDB.Driver.Core.Tests/Core/Authentication/MongoDBCRAuthenticatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void Authenticate_should_not_throw_when_authentication_succeeds(
103103
}
104104

105105
act.ShouldNotThrow();
106-
SpinWait.SpinUntil(() => connection.GetSentMessages().Count >= 2, 100).Should().BeTrue();
106+
SpinWait.SpinUntil(() => connection.GetSentMessages().Count >= 2, TimeSpan.FromSeconds(5)).Should().BeTrue();
107107

108108
var sentMessages = MessageHelper.TranslateMessagesToBsonDocuments(connection.GetSentMessages());
109109
sentMessages.Count.Should().Be(2);

tests/MongoDB.Driver.Core.Tests/Core/Authentication/PlainAuthenticatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void Authenticate_should_not_throw_when_authentication_succeeds(
9999
}
100100

101101
act.ShouldNotThrow();
102-
SpinWait.SpinUntil(() => connection.GetSentMessages().Count >= 1, 100).Should().BeTrue();
102+
SpinWait.SpinUntil(() => connection.GetSentMessages().Count >= 1, TimeSpan.FromSeconds(5)).Should().BeTrue();
103103

104104
var sentMessages = MessageHelper.TranslateMessagesToBsonDocuments(connection.GetSentMessages());
105105
sentMessages.Count.Should().Be(1);

tests/MongoDB.Driver.Core.Tests/Core/Authentication/ScramSha1AuthenticatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void Authenticate_should_not_throw_when_authentication_succeeds(
163163
}
164164

165165
act.ShouldNotThrow();
166-
SpinWait.SpinUntil(() => connection.GetSentMessages().Count >= 2, 100).Should().BeTrue();
166+
SpinWait.SpinUntil(() => connection.GetSentMessages().Count >= 2, TimeSpan.FromSeconds(5)).Should().BeTrue();
167167

168168
var sentMessages = MessageHelper.TranslateMessagesToBsonDocuments(connection.GetSentMessages());
169169
sentMessages.Count.Should().Be(2);

tests/MongoDB.Driver.Core.Tests/Core/Clusters/MultiServerClusterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void Should_remove_a_server_whose_canonical_end_point_does_not_match_its_
188188
PublishDescription(subject, nonCanonicalEndPoint, ServerType.ReplicaSetPrimary,
189189
hosts: new[] { _firstEndPoint, _secondEndPoint },
190190
canonicalEndPoint: _firstEndPoint);
191-
SpinWait.SpinUntil(() => !subject.Description.Servers.Any(d => ((DnsEndPoint)d.EndPoint).Host == "wrong"), 100).Should().BeTrue();
191+
SpinWait.SpinUntil(() => !subject.Description.Servers.Any(d => ((DnsEndPoint)d.EndPoint).Host == "wrong"), TimeSpan.FromSeconds(5)).Should().BeTrue();
192192

193193
var description = subject.Description;
194194
description.State.Should().Be(ClusterState.Disconnected);
@@ -580,7 +580,7 @@ public void Should_call_initialize_on_all_servers()
580580

581581
PublishDescription(subject, _firstEndPoint, ServerType.ReplicaSetPrimary,
582582
hosts: new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint });
583-
SpinWait.SpinUntil(() => subject.Description.Servers.Count == 3, 100).Should().BeTrue();
583+
SpinWait.SpinUntil(() => subject.Description.Servers.Count == 3, TimeSpan.FromSeconds(5)).Should().BeTrue();
584584

585585
foreach (var endPoint in new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint })
586586
{

tests/MongoDB.Driver.Core.Tests/Core/ConnectionPools/ExclusiveConnectionPoolTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private void InitializeAndWait()
440440
_subject.AvailableCount == _settings.MaxConnections &&
441441
_subject.DormantCount == _settings.MinConnections &&
442442
_subject.UsedCount == 0,
443-
TimeSpan.FromSeconds(4))
443+
TimeSpan.FromSeconds(5))
444444
.Should().BeTrue();
445445

446446
_subject.AvailableCount.Should().Be(_settings.MaxConnections);

tests/MongoDB.Driver.Core.Tests/Core/Connections/BinaryConnectionTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void Open_should_not_complete_the_second_call_until_the_first_is_complete
185185
{
186186
openTask1 = Task.Run(() => _subject.Open(CancellationToken.None));
187187
}
188-
SpinWait.SpinUntil(() => task1IsBlocked, 1000).Should().BeTrue();
188+
SpinWait.SpinUntil(() => task1IsBlocked, TimeSpan.FromSeconds(5)).Should().BeTrue();
189189

190190
Task openTask2;
191191
if (async2)
@@ -202,8 +202,8 @@ public void Open_should_not_complete_the_second_call_until_the_first_is_complete
202202
_subject.Description.Should().BeNull();
203203

204204
completionSource.SetResult(new Mock<Stream>().Object);
205-
SpinWait.SpinUntil(() => openTask1.IsCompleted, 1000).Should().BeTrue();
206-
SpinWait.SpinUntil(() => openTask2.IsCompleted, 1000).Should().BeTrue();
205+
SpinWait.SpinUntil(() => openTask1.IsCompleted, TimeSpan.FromSeconds(5)).Should().BeTrue();
206+
SpinWait.SpinUntil(() => openTask2.IsCompleted, TimeSpan.FromSeconds(5)).Should().BeTrue();
207207
_subject.Description.Should().NotBeNull();
208208

209209
_capturedEvents.Next().Should().BeOfType<ConnectionOpeningEvent>();
@@ -393,7 +393,7 @@ public void ReceiveMessage_should_handle_out_of_order_replies(
393393
{
394394
var receivedTask10IsRunning = 0;
395395
receivedTask10 = Task.Run(() => { Interlocked.Exchange(ref receivedTask10IsRunning, 1); return _subject.ReceiveMessage(10, encoderSelector, _messageEncoderSettings, CancellationToken.None); });
396-
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref receivedTask10IsRunning, 0, 0) == 1, 1000).Should().BeTrue();
396+
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref receivedTask10IsRunning, 0, 0) == 1, TimeSpan.FromSeconds(5)).Should().BeTrue();
397397
}
398398

399399
Task<ResponseMessage> receivedTask11;
@@ -405,7 +405,7 @@ public void ReceiveMessage_should_handle_out_of_order_replies(
405405
{
406406
var receivedTask11IsRunning = 0;
407407
receivedTask11 = Task.Run(() => { Interlocked.Exchange(ref receivedTask11IsRunning, 1); return _subject.ReceiveMessage(11, encoderSelector, _messageEncoderSettings, CancellationToken.None); });
408-
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref receivedTask11IsRunning, 0, 0) == 1, 1000).Should().BeTrue();
408+
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref receivedTask11IsRunning, 0, 0) == 1, TimeSpan.FromSeconds(5)).Should().BeTrue();
409409
}
410410

411411
var messageToReceive10 = MessageHelper.BuildReply<BsonDocument>(new BsonDocument("_id", 10), BsonDocumentSerializer.Instance, responseTo: 10);
@@ -460,7 +460,7 @@ public void ReceiveMessage_should_throw_network_exception_to_all_awaiters(
460460
{
461461
var task1IsRunning = 0;
462462
task1 = Task.Run(() => { Interlocked.Exchange(ref task1IsRunning, 1); return _subject.ReceiveMessage(1, encoderSelector, _messageEncoderSettings, CancellationToken.None); });
463-
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref task1IsRunning, 0, 0) == 1, 1000).Should().BeTrue();
463+
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref task1IsRunning, 0, 0) == 1, TimeSpan.FromSeconds(5)).Should().BeTrue();
464464
}
465465

466466
Task task2;
@@ -472,7 +472,7 @@ public void ReceiveMessage_should_throw_network_exception_to_all_awaiters(
472472
{
473473
var task2IsRunning = 0;
474474
task2 = Task.Run(() => { Interlocked.Exchange(ref task2IsRunning, 1); return _subject.ReceiveMessage(2, encoderSelector, _messageEncoderSettings, CancellationToken.None); });
475-
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref task2IsRunning, 0, 0) == 1, 1000).Should().BeTrue();
475+
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref task2IsRunning, 0, 0) == 1, TimeSpan.FromSeconds(5)).Should().BeTrue();
476476
}
477477

478478
readTcs.SetException(new SocketException());
@@ -694,7 +694,7 @@ public void SendMessageshould_throw_MongoConnectionClosedException_for_waiting_t
694694
task1 = Task.Run(() => { _subject.SendMessage(message1, _messageEncoderSettings, CancellationToken.None); });
695695
}
696696

697-
SpinWait.SpinUntil(() => task1IsBlocked, 1000).Should().BeTrue();
697+
SpinWait.SpinUntil(() => task1IsBlocked, TimeSpan.FromSeconds(5)).Should().BeTrue();
698698
task1IsBlocked.Should().BeTrue();
699699

700700
Task task2;
@@ -706,7 +706,7 @@ public void SendMessageshould_throw_MongoConnectionClosedException_for_waiting_t
706706
{
707707
var task2IsRunning = 0;
708708
task2 = Task.Run(() => { Interlocked.Exchange(ref task2IsRunning, 1); _subject.SendMessage(message2, _messageEncoderSettings, CancellationToken.None); });
709-
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref task2IsRunning, 0, 0) == 1, 1000).Should().BeTrue();
709+
SpinWait.SpinUntil(() => Interlocked.CompareExchange(ref task2IsRunning, 0, 0) == 1, TimeSpan.FromSeconds(5)).Should().BeTrue();
710710
}
711711

712712
writeTcs.SetException(new SocketException());

tests/MongoDB.Driver.Core.Tests/Core/Misc/SemaphoreSlimRequestTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void Task_should_be_cancelled_when_cancellationToken_requests_cancellatio
101101
var subject = new SemaphoreSlimRequest(semaphore, cancellationTokenSource.Token);
102102

103103
cancellationTokenSource.Cancel();
104-
SpinWait.SpinUntil(() => subject.Task.IsCompleted, 1000).Should().BeTrue();
104+
SpinWait.SpinUntil(() => subject.Task.IsCompleted, TimeSpan.FromSeconds(5)).Should().BeTrue();
105105
semaphore.Release();
106106

107107
subject.Task.Status.Should().Be(TaskStatus.Canceled);
@@ -116,7 +116,7 @@ public void Task_should_be_completed_when_semaphore_becomes_available()
116116
var subject = new SemaphoreSlimRequest(semaphore, CancellationToken.None);
117117

118118
semaphore.Release();
119-
SpinWait.SpinUntil(() => subject.Task.IsCompleted, 1000).Should().BeTrue();
119+
SpinWait.SpinUntil(() => subject.Task.IsCompleted, TimeSpan.FromSeconds(5)).Should().BeTrue();
120120

121121
subject.Task.Status.Should().Be(TaskStatus.RanToCompletion);
122122
semaphore.CurrentCount.Should().Be(0);

tests/MongoDB.Driver.Core.Tests/Core/Servers/ServerMonitorTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void DescriptionChanged_should_be_raised_when_moving_from_disconnected_to
117117

118118
SetupHeartbeatConnection();
119119
_subject.Initialize();
120-
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(4)).Should().BeTrue();
120+
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(5)).Should().BeTrue();
121121

122122
changes.Count.Should().Be(1);
123123
changes[0].OldServerDescription.State.Should().Be(ServerState.Disconnected);
@@ -133,7 +133,7 @@ public void Description_should_be_connected_after_successful_heartbeat()
133133
{
134134
SetupHeartbeatConnection();
135135
_subject.Initialize();
136-
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(4)).Should().BeTrue();
136+
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(5)).Should().BeTrue();
137137

138138
_subject.Description.State.Should().Be(ServerState.Connected);
139139
_subject.Description.Type.Should().Be(ServerType.Standalone);
@@ -148,14 +148,14 @@ public void RequestHeartbeat_should_force_another_heartbeat()
148148
{
149149
SetupHeartbeatConnection();
150150
_subject.Initialize();
151-
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(4)).Should().BeTrue();
151+
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(5)).Should().BeTrue();
152152
_capturedEvents.Clear();
153153

154154
_subject.RequestHeartbeat();
155155

156156
// the next requests down heartbeat connection will fail, so the state should
157157
// go back to disconnected
158-
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Disconnected, TimeSpan.FromSeconds(4)).Should().BeTrue();
158+
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Disconnected, TimeSpan.FromSeconds(5)).Should().BeTrue();
159159

160160
// when heart fails, we immediately attempt a second, hence the multiple events...
161161
_capturedEvents.Next().Should().BeOfType<ServerHeartbeatStartedEvent>();
@@ -170,7 +170,7 @@ public void Invalidate_should_do_everything_invalidate_is_supposed_to_do()
170170
{
171171
SetupHeartbeatConnection();
172172
_subject.Initialize();
173-
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(4)).Should().BeTrue();
173+
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Connected, TimeSpan.FromSeconds(5)).Should().BeTrue();
174174
_capturedEvents.Clear();
175175

176176
_subject.Invalidate();
@@ -179,8 +179,8 @@ public void Invalidate_should_do_everything_invalidate_is_supposed_to_do()
179179

180180
// the next requests down heartbeat connection will fail, so the state should
181181
// go back to disconnected
182-
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Disconnected, TimeSpan.FromSeconds(4)).Should().BeTrue();
183-
SpinWait.SpinUntil(() => _capturedEvents.Count >= 4, TimeSpan.FromSeconds(4)).Should().BeTrue();
182+
SpinWait.SpinUntil(() => _subject.Description.State == ServerState.Disconnected, TimeSpan.FromSeconds(5)).Should().BeTrue();
183+
SpinWait.SpinUntil(() => _capturedEvents.Count >= 4, TimeSpan.FromSeconds(5)).Should().BeTrue();
184184

185185
// when heart fails, we immediately attempt a second, hence the multiple events...
186186
_capturedEvents.Next().Should().BeOfType<ServerHeartbeatStartedEvent>();

tests/MongoDB.Driver.Legacy.Tests/MongoCollectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ public void TestInsertBatchMultipleBatchesWriteConcernDisabledContinueOnErrorTru
22302230

22312231
for (int i = 1; i <= 5; i++)
22322232
{
2233-
if (!SpinWait.SpinUntil(() => collection.Count(Query.EQ("_id", i)) == 1, TimeSpan.FromSeconds(4)))
2233+
if (!SpinWait.SpinUntil(() => collection.Count(Query.EQ("_id", i)) == 1, TimeSpan.FromSeconds(5)))
22342234
{
22352235
Assert.True(false, $"_id {i} does not exist.");
22362236
}

tests/MongoDB.Driver.Tests/MongoClientSettingsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public void TestSocketConfigurator()
524524
settings.ClusterConfigurator = cb => cb.ConfigureTcp(tcp => tcp.With(socketConfigurator: socketConfigurator));
525525
var subject = new MongoClient(settings);
526526

527-
SpinWait.SpinUntil(() => subject.Cluster.Description.State == ClusterState.Connected, TimeSpan.FromSeconds(4)).Should().BeTrue();
527+
SpinWait.SpinUntil(() => subject.Cluster.Description.State == ClusterState.Connected, TimeSpan.FromSeconds(5)).Should().BeTrue();
528528

529529
Assert.True(socketConfiguratorWasCalled);
530530
}

0 commit comments

Comments
 (0)