@@ -47,7 +47,9 @@ public void Connection_pool_should_be_cleared_when_Shutdown_exceptions(
4747 {
4848 RequireServer . Check ( ) . Supports ( Feature . FailPointsFailCommand ) . ClusterType ( ClusterType . ReplicaSet ) ;
4949
50- var eventCapturer = new EventCapturer ( ) . Capture < ConnectionPoolRemovedConnectionEvent > ( ) ;
50+ var eventCapturer = new EventCapturer ( )
51+ . Capture < ConnectionPoolClearedEvent > ( )
52+ . Capture < ConnectionCreatedEvent > ( ) ;
5153 using ( var client = CreateDisposableClient ( eventCapturer ) )
5254 {
5355 var database = client . GetDatabase ( _databaseName , new MongoDatabaseSettings { WriteConcern = WriteConcern . WMajority } ) ;
@@ -61,8 +63,14 @@ public void Connection_pool_should_be_cleared_when_Shutdown_exceptions(
6163
6264 var e = exception . Should ( ) . BeOfType < MongoNodeIsRecoveringException > ( ) . Subject ;
6365 e . Code . Should ( ) . Be ( errorCode ) ;
66+
67+ eventCapturer . Next ( ) . Should ( ) . BeOfType < ConnectionPoolClearedEvent > ( ) ;
68+ eventCapturer . Events . Should ( ) . BeEmpty ( ) ;
69+
70+ collection . InsertOne ( new BsonDocument ( "test" , 1 ) ) ;
71+ eventCapturer . Next ( ) . Should ( ) . BeOfType < ConnectionCreatedEvent > ( ) ;
72+ eventCapturer . Events . Should ( ) . BeEmpty ( ) ;
6473 }
65- eventCapturer . Events . Count . Should ( ) . Be ( 1 ) ;
6674 }
6775 }
6876
@@ -72,7 +80,7 @@ public void Connection_pool_should_not_be_cleared_when_replSetStepDown_and_GetMo
7280 {
7381 RequireServer . Check ( ) . Supports ( Feature . KeepConnectionPoolWhenReplSetStepDown ) . ClusterType ( ClusterType . ReplicaSet ) ;
7482
75- var eventCapturer = new EventCapturer ( ) . Capture < ConnectionPoolRemovedConnectionEvent > ( ) ;
83+ var eventCapturer = new EventCapturer ( ) . Capture < ConnectionPoolClearedEvent > ( ) ;
7684 using ( var client = CreateDisposableClient ( eventCapturer ) )
7785 {
7886 var database = client . GetDatabase ( _databaseName , new MongoDatabaseSettings { WriteConcern = WriteConcern . WMajority } ) ;
@@ -99,7 +107,7 @@ public void Connection_pool_should_not_be_cleared_when_replSetStepDown_and_GetMo
99107 RunOnSecondary ( client , secondary . EndPoint , BsonDocument . Parse ( "{ replSetFreeze : 0 }" ) ) ;
100108 }
101109
102- var replSetStepDownCommand = BsonDocument . Parse ( "{ replSetStepDown : 20 , force : true }" ) ;
110+ var replSetStepDownCommand = BsonDocument . Parse ( "{ replSetStepDown : 30 , force : true }" ) ;
103111 BsonDocument replSetStepDownResult ;
104112 if ( async)
105113 {
@@ -115,7 +123,7 @@ public void Connection_pool_should_not_be_cleared_when_replSetStepDown_and_GetMo
115123
116124 cursor . MoveNext ( ) ;
117125
118- eventCapturer . Events . Should ( ) . BeEmpty ( ) ;
126+ eventCapturer . Events . Should ( ) . BeEmpty ( ) ; // it also means that no new PoolClearedEvent
119127 }
120128
121129 void RunOnSecondary ( IMongoClient primaryClient , EndPoint secondaryEndpoint , BsonDocument command )
@@ -142,7 +150,9 @@ public void Connection_pool_should_work_as_expected_when_NonMaster_exception()
142150
143151 var shouldConnectionPoolBeCleared = ! Feature. KeepConnectionPoolWhenNotMasterConnectionException. IsSupported( CoreTestConfiguration . ServerVersion ) ;
144152
145- var eventCapturer = new EventCapturer( ) . Capture < ConnectionPoolRemovedConnectionEvent > ( ) ;
153+ var eventCapturer = new EventCapturer( )
154+ . Capture < ConnectionPoolClearedEvent > ( )
155+ . Capture < ConnectionCreatedEvent > ( ) ;
146156 using ( var client = CreateDisposableClient( eventCapturer ) )
147157 {
148158 var database = client. GetDatabase( _databaseName , new MongoDatabaseSettings { WriteConcern = WriteConcern. WMajority } ) ;
@@ -152,18 +162,28 @@ public void Connection_pool_should_work_as_expected_when_NonMaster_exception()
152162
153163 using ( ConfigureFailPoint ( client , 10107 ) )
154164 {
155- var document = new BsonDocument( "test ", 1 ) ;
156- var exception = Record. Exception( ( ) => { collection . InsertOne ( document ) ; } ) ;
165+ var exception = Record. Exception( ( ) => { collection . InsertOne ( new BsonDocument ( "test", 1 ) ) ; } ) ;
157166
158167 var e = exception. Should( ) . BeOfType < MongoNotPrimaryException > ( ) . Subject ;
159168 e . Code . Should ( ) . Be ( 10107 ) ;
160169
161- if ( ! shouldConnectionPoolBeCleared )
170+ if ( shouldConnectionPoolBeCleared )
171+ {
172+ eventCapturer . Next ( ) . Should ( ) . BeOfType < ConnectionPoolClearedEvent > ( ) ;
173+ eventCapturer . Events . Should ( ) . BeEmpty ( ) ;
174+ }
175+ else
176+ {
177+ eventCapturer . Events . Should ( ) . BeEmpty ( ) ;
178+ }
179+
180+ collection . InsertOne ( new BsonDocument ( "test", 1 ) ) ;
181+ if ( shouldConnectionPoolBeCleared )
162182 {
163- collection . InsertOne ( document ) ;
183+ eventCapturer . Next ( ) . Should ( ) . BeOfType < ConnectionCreatedEvent > ( ) ;
164184 }
185+ eventCapturer . Events . Should ( ) . BeEmpty ( ) ;
165186 }
166- eventCapturer . Events . Count . Should ( ) . Be ( shouldConnectionPoolBeCleared ? 1 : 0 ) ;
167187 }
168188 }
169189
0 commit comments