[CSHARP-2109] Race condition in Drivers.Core.BinaryConnectionTests Created: 22/Nov/17  Updated: 28/Oct/23  Resolved: 28/Nov/17

Status: Closed
Project: C# Driver
Component/s: Testing
Affects Version/s: None
Fix Version/s: 2.5

Type: Bug Priority: Major - P3
Reporter: Vincent Kam (Inactive) Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

There appears to be a race condition in Drivers.Core.BinaryConnectionTests that makes the test fail on certain runs and pass on others.

Specifically: MongoDB.Driver.Core.Connections.BinaryConnectionTests.SendMessageshould_throw_MongoConnectionClosedException_for_waiting_tasks

On the same patch:
Failure:
https://evergreen.mongodb.com/task_log_raw/dot_net_driver_tests__version~2.6_os~windows_64_topology~standalone_auth~auth_ssl~nossl_test_patch_1c20602fb9e95e393c452e91109caa467c541c84_5a15923c2a60ed07c5002abc_17_11_22_15_06_17/0?type=T
Pass:
https://evergreen.mongodb.com/task_log_raw/dot_net_driver_tests__version~2.6_os~windows_64_topology~standalone_auth~auth_ssl~nossl_test_patch_1c20602fb9e95e393c452e91109caa467c541c84_5a15923c2a60ed07c5002abc_17_11_22_15_06_17/1?type=T



 Comments   
Comment by Githook User [ 28/Nov/17 ]

Author:

{'name': 'rstam', 'username': 'rstam', 'email': 'robert@robertstam.org'}

Message: CSHARP-2109: Fix race condition in BinaryConnectionTests.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/ae4c63065979bc105cab4c4a36bb9dbf2867cfa1

Comment by Robert Stam [ 23/Nov/17 ]

Extracting the setup code from the constructor to a helper method that can be called every iteration I am able to run the test as many times as I want.

The first run of 10,000 iterations did not fail, but the second run did, so this can be reproduced locally.

Comment by Robert Stam [ 23/Nov/17 ]

Even iterating just 2 times causes the test to fail.

It turns out that these tests can't be run more than once because they depend on setup that is happening in the constructor, so the 2nd iteration isn't being properly initialized.

I didn't realize this at first because when looking at the test it wasn't obvious that there was some initialization happening somewhere else.

Comment by Robert Stam [ 23/Nov/17 ]

I can reliably make this test fail by putting the entire test body inside a for loop and iterating 1000 times.

However, it is failing in a different way. The first SpinUntil is timing out.

Comment by Robert Stam [ 23/Nov/17 ]

Here are the relevant lines from the log file:

 [2017/11/22 11:20:27.057] Failed   MongoDB.Driver.Core.Connections.BinaryConnectionTests.SendMessageshould_throw_MongoConnectionClosedException_for_waiting_tasks(async1: True, async2: False)
 [2017/11/22 11:20:27.057] Error Message:
 [2017/11/22 11:20:27.057]  Expected type to be MongoDB.Driver.Core.Events.ConnectionSendingMessagesEvent, but found MongoDB.Driver.Core.Events.ConnectionFailedEvent.
 [2017/11/22 11:20:27.057] Stack Trace:
 [2017/11/22 11:20:27.057]    at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
 [2017/11/22 11:20:27.057]    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
 [2017/11/22 11:20:27.057]    at FluentAssertions.Types.TypeAssertions.Be(Type expected, String because, Object[] becauseArgs)
 [2017/11/22 11:20:27.057]    at FluentAssertions.Primitives.ReferenceTypeAssertions`2.BeOfType(Type expectedType, String because, Object[] becauseArgs)
 [2017/11/22 11:20:27.057]    at FluentAssertions.Primitives.ReferenceTypeAssertions`2.BeOfType[T](String because, Object[] becauseArgs)
 [2017/11/22 11:20:27.057]    at MongoDB.Driver.Core.Connections.BinaryConnectionTests.SendMessageshould_throw_MongoConnectionClosedException_for_waiting_tasks(Boolean async1, Boolean async2) in C:\data\mci\4864f98f59d47dc62b14c0ef0b797e30\mongo-csharp-driver\tests\MongoDB.Driver.Core.Tests\Core\Connections\BinaryConnectionTests.cs:line 720
 [2017/11/22 11:20:47.771] Total tests: 3881. Passed: 3880. Failed: 1. Skipped: 0.

Generated at Wed Feb 07 21:41:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.