@@ -33,7 +33,7 @@ import static com.mongodb.ClusterFixture.serverVersionAtLeast
3333import static com.mongodb.Fixture.getDefaultDatabaseName
3434import static com.mongodb.Fixture.getMongoClientURI
3535
36- class MongoClientsSpecification extends FunctionalSpecification {
36+ class MongoClientsSpecification extends FunctionalSpecification {
3737 @IgnoreIf ({ !serverVersionAtLeast(3 , 4 ) || !isStandalone() })
3838 def ' application name should appear in the system.profile collection' () {
3939 given :
@@ -64,17 +64,22 @@ class MongoClientsSpecification extends FunctionalSpecification {
6464 @IgnoreIf ({ !isDiscoverableReplicaSet() })
6565 def ' should use server selector from MongoClientOptions' () {
6666 given :
67- def expectedWinner
67+ def expectedWinningAddresses = [] as Set
6868 def actualWinningAddresses = [] as Set
6969 def optionsBuilder = MongoClientOptions . builder()
7070 // select the suitable server with the highest port number
7171 .serverSelector { ClusterDescription clusterDescription ->
72+ def highestPortServer
7273 for (ServerDescription cur : clusterDescription. getServerDescriptions()) {
73- if (expectedWinner == null || cur. address. port > expectedWinner . address. port) {
74- expectedWinner = cur
74+ if (highestPortServer == null || cur. address. port > highestPortServer . address. port) {
75+ highestPortServer = cur
7576 }
7677 }
77- expectedWinner == null ? [] : [expectedWinner]
78+ if (highestPortServer == null ) {
79+ return []
80+ }
81+ expectedWinningAddresses. add(highestPortServer. address)
82+ [highestPortServer]
7883 }. addCommandListener(new CommandListener () {
7984 // record each address actually used
8085 @Override
@@ -101,7 +106,6 @@ class MongoClientsSpecification extends FunctionalSpecification {
101106 }
102107
103108 then :
104- actualWinningAddresses. size() == 1
105- actualWinningAddresses. contains(expectedWinner. address)
109+ actualWinningAddresses == expectedWinningAddresses
106110 }
107111}
0 commit comments