1818using System . Linq ;
1919using System . Net ;
2020using System . Reflection ;
21- using System . Threading ;
22- using System . Threading . Tasks ;
2321using FluentAssertions ;
24- using MongoDB . Driver . Core . Bindings ;
2522using MongoDB . Driver . Core . Clusters ;
26- using MongoDB . Driver . Core . Clusters . ServerSelectors ;
27- using MongoDB . Driver . Core . Configuration ;
2823using MongoDB . Driver . Core . Misc ;
2924using MongoDB . Driver . Core . Servers ;
30- using MongoDB . Driver . Encryption ;
3125using Moq ;
3226using Xunit ;
3327
@@ -205,35 +199,23 @@ public void ReleaseSession_should_have_expected_result(int[] pooledSessionWasRec
205199 }
206200 }
207201
208- [ Fact ]
209- public void IsAboutToExpire_should_never_expire_in_load_balancing_mode ( )
210- {
211- var subject = CreateSubject ( ) ;
212- var mockedCluster = new TestCluster ( ClusterType . LoadBalanced ) ;
213- var mockedServerSessionPool = new CoreServerSessionPool ( mockedCluster ) ;
214- var mockSession = new Mock < ICoreServerSession > ( ) ;
215- var lastUsedAt = DateTime . UtcNow . AddSeconds ( 1741 ) ;
216- mockSession . SetupGet ( m => m . LastUsedAt ) . Returns ( lastUsedAt ) ;
217-
218- var result = mockedServerSessionPool . IsAboutToExpire ( mockSession . Object ) ;
219-
220- result . Should ( ) . BeFalse ( ) ;
221- }
222-
223202 [ Theory ]
224- [ InlineData ( null , true ) ]
225- [ InlineData ( 1741 , true ) ]
226- [ InlineData ( 1739 , false ) ]
227- public void IsAboutToExpire_should_return_expected_result ( int ? lastUsedSecondsAgo , bool expectedResult )
203+ [ InlineData ( ClusterType . Sharded , null , true ) ]
204+ [ InlineData ( ClusterType . Sharded , 1741 , true ) ]
205+ [ InlineData ( ClusterType . Sharded , 1739 , false ) ]
206+ [ InlineData ( ClusterType . LoadBalanced , null , false ) ]
207+ [ InlineData ( ClusterType . LoadBalanced , 1741 , false ) ]
208+ [ InlineData ( ClusterType . LoadBalanced , 1739 , false ) ]
209+ public void IsAboutToExpire_should_return_expected_result ( ClusterType clusterType , int ? lastUsedSecondsAgo , bool isAboutToExpire )
228210 {
229- var subject = CreateSubject ( ) ;
211+ var subject = CreateSubject ( clusterType ) ;
230212 var mockSession = new Mock < ICoreServerSession > ( ) ;
231213 var lastUsedAt = lastUsedSecondsAgo == null ? ( DateTime ? ) null : DateTime . UtcNow . AddSeconds ( - lastUsedSecondsAgo . Value ) ;
232214 mockSession . SetupGet ( m => m . LastUsedAt ) . Returns ( lastUsedAt ) ;
233215
234216 var result = subject . IsAboutToExpire ( mockSession . Object ) ;
235217
236- result . Should ( ) . Be ( expectedResult ) ;
218+ result . Should ( ) . Be ( isAboutToExpire ) ;
237219 }
238220
239221 // private methods
@@ -256,7 +238,7 @@ private Mock<ICoreServerSession> CreateMockSession(bool recentlyUsed)
256238 return recentlyUsed ? CreateMockRecentlyUsedSession ( ) : CreateMockExpiredSession ( ) ;
257239 }
258240
259- private CoreServerSessionPool CreateSubject ( )
241+ private CoreServerSessionPool CreateSubject ( ClusterType clusterType = ClusterType . Sharded )
260242 {
261243 var clusterId = new ClusterId ( ) ;
262244 var endPoint = new DnsEndPoint ( "localhost" , 27017 ) ;
@@ -270,36 +252,13 @@ private CoreServerSessionPool CreateSubject()
270252 version : new SemanticVersion ( 3 , 6 , 0 ) ,
271253 wireVersionRange : new Range < int > ( 6 , 14 ) ) ;
272254
273- var clusterDescription = new ClusterDescription ( clusterId , false , null , ClusterType . Sharded , [ serverDescription ] ) ;
255+ var clusterDescription = new ClusterDescription ( clusterId , false , null , clusterType , [ serverDescription ] ) ;
274256
275257 var mockCluster = new Mock < IClusterInternal > ( ) ;
276258 mockCluster . SetupGet ( m => m . Description ) . Returns ( clusterDescription ) ;
277259
278260 return new CoreServerSessionPool ( mockCluster . Object ) ;
279261 }
280-
281- private class TestCluster : IClusterInternal
282- {
283- public TestCluster ( ClusterType clusterType )
284- {
285- Description = new ClusterDescription ( new ClusterId ( ) , false , null , clusterType , Enumerable . Empty < ServerDescription > ( ) ) ;
286- }
287-
288- public ClusterId ClusterId => throw new NotImplementedException ( ) ;
289-
290- public ClusterDescription Description { get ; }
291-
292- public ClusterSettings Settings => throw new NotImplementedException ( ) ;
293-
294- public event EventHandler < ClusterDescriptionChangedEventArgs > DescriptionChanged ;
295-
296- public ICoreServerSession AcquireServerSession ( ) => throw new NotImplementedException ( ) ;
297- public void Dispose ( ) => throw new NotImplementedException ( ) ;
298- public void Initialize ( ) => DescriptionChanged ? . Invoke ( this , new ClusterDescriptionChangedEventArgs ( Description , Description ) ) ;
299- public IServer SelectServer ( IServerSelector selector , CancellationToken cancellationToken ) => throw new NotImplementedException ( ) ;
300- public Task < IServer > SelectServerAsync ( IServerSelector selector , CancellationToken cancellationToken ) => throw new NotImplementedException ( ) ;
301- public ICoreSessionHandle StartSession ( CoreSessionOptions options = null ) => throw new NotImplementedException ( ) ;
302- }
303262 }
304263
305264 internal static class CoreServerSessionPoolReflector
0 commit comments