Skip to content

Commit fb6388c

Browse files
authored
Build: Fix slow tests (#773)
JAVA-4145
1 parent e55594d commit fb6388c

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ configure(javaCodeCheckedProjects) {
230230
testImplementation('org.junit.jupiter:junit-jupiter')
231231
testImplementation('org.junit.vintage:junit-vintage-engine')
232232

233-
testImplementation platform('org.spockframework:spock-bom:2.0-M3-groovy-2.5')
233+
testImplementation platform('org.spockframework:spock-bom:2.0-groovy-2.5')
234234
testImplementation 'org.spockframework:spock-core'
235235
testImplementation 'org.spockframework:spock-junit4'
236236
testImplementation("org.mockito:mockito-core:3.8.0")
@@ -274,10 +274,17 @@ configure(javaCodeCheckedProjects) {
274274
}
275275

276276
task testSlowOnly(type: Test) {
277+
dependsOn('testSlowGroovy')
277278
useJUnitPlatform {
278-
includeEngines('junit-jupiter', 'junit-vintage', 'spock')
279+
includeEngines('junit-jupiter', 'junit-vintage')
279280
includeTags('Slow')
280281
}
282+
}
283+
284+
task testSlowGroovy(type: Test) {
285+
useJUnitPlatform {
286+
includeEngines( 'spock')
287+
}
281288
systemProperty('spock.configuration', "${configDir}/spock/OnlySlow.groovy")
282289
}
283290

driver-core/src/test/functional/com/mongodb/internal/connection/AsyncStreamTimeoutsSpecification.groovy

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.mongodb.MongoSocketReadTimeoutException
2121
import com.mongodb.OperationFunctionalSpecification
2222
import com.mongodb.ServerAddress
2323
import com.mongodb.connection.AsynchronousSocketChannelStreamFactory
24+
import com.mongodb.connection.ClusterConnectionMode
2425
import com.mongodb.connection.ClusterId
2526
import com.mongodb.connection.ServerId
2627
import com.mongodb.connection.SocketSettings
@@ -39,7 +40,6 @@ import static com.mongodb.ClusterFixture.getServerApi
3940
import static com.mongodb.ClusterFixture.getSslSettings
4041
import static com.mongodb.internal.connection.CommandHelper.executeCommand
4142

42-
@IgnoreIf({ System.getProperty('ignoreSlowUnitTests') == 'true' })
4343
@Slow
4444
class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification {
4545

@@ -49,9 +49,9 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification
4949
@IgnoreIf({ getSslSettings().isEnabled() })
5050
def 'should throw a MongoSocketOpenException when the AsynchronousSocket Stream fails to open'() {
5151
given:
52-
def connection = new InternalStreamConnectionFactory(
52+
def connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
5353
new AsynchronousSocketChannelStreamFactory(openSocketSettings, getSslSettings()), getCredentialWithCache(), null, null,
54-
[], getServerApi())
54+
[], null, getServerApi())
5555
.create(new ServerId(new ClusterId(), new ServerAddress(new InetSocketAddress('192.168.255.255', 27017))))
5656

5757
when:
@@ -64,17 +64,17 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification
6464
@IgnoreIf({ getSslSettings().isEnabled() })
6565
def 'should throw a MongoSocketReadTimeoutException with the AsynchronousSocket stream'() {
6666
given:
67-
def connection = new InternalStreamConnectionFactory(
67+
def connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
6868
new AsynchronousSocketChannelStreamFactory(readSocketSettings, getSslSettings()), getCredentialWithCache(), null, null,
69-
[], getServerApi(),).create(new ServerId(new ClusterId(), getPrimary()))
69+
[], null, getServerApi()).create(new ServerId(new ClusterId(), getPrimary()))
7070
connection.open()
7171

7272
getCollectionHelper().insertDocuments(new BsonDocument('_id', new BsonInt32(1)));
7373
def countCommand = new BsonDocument('count', new BsonString(getCollectionName()))
7474
countCommand.put('query', new BsonDocument('$where', new BsonString('sleep(5050); return true;')))
7575

7676
when:
77-
executeCommand(getDatabaseName(), countCommand, connection)
77+
executeCommand(getDatabaseName(), countCommand, getServerApi(), connection)
7878

7979
then:
8080
thrown(MongoSocketReadTimeoutException)
@@ -85,9 +85,10 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification
8585

8686
def 'should throw a MongoSocketOpenException when the Netty Stream fails to open'() {
8787
given:
88-
def connection = new InternalStreamConnectionFactory(
89-
new NettyStreamFactory(openSocketSettings, getSslSettings()), getCredentialWithCache(), null, null, [], getServerApi(),
90-
).create(new ServerId(new ClusterId(), new ServerAddress(new InetSocketAddress('192.168.255.255', 27017))))
88+
def connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
89+
new NettyStreamFactory(openSocketSettings, getSslSettings()), getCredentialWithCache(), null, null,
90+
[], null, getServerApi()).create(new ServerId(new ClusterId(),
91+
new ServerAddress(new InetSocketAddress('192.168.255.255', 27017))))
9192

9293
when:
9394
connection.open()
@@ -99,17 +100,17 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification
99100

100101
def 'should throw a MongoSocketReadTimeoutException with the Netty stream'() {
101102
given:
102-
def connection = new InternalStreamConnectionFactory(
103-
new NettyStreamFactory(readSocketSettings, getSslSettings()), getCredentialWithCache(), null, null, [], getServerApi(),
104-
).create(new ServerId(new ClusterId(), getPrimary()), connectionGeneration)
103+
def connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
104+
new NettyStreamFactory(readSocketSettings, getSslSettings()), getCredentialWithCache(), null, null,
105+
[], null, getServerApi()).create(new ServerId(new ClusterId(), getPrimary()))
105106
connection.open()
106107

107108
getCollectionHelper().insertDocuments(new BsonDocument('_id', new BsonInt32(1)));
108109
def countCommand = new BsonDocument('count', new BsonString(getCollectionName()))
109110
countCommand.put('query', new BsonDocument('$where', new BsonString('sleep(5050); return true;')))
110111

111112
when:
112-
executeCommand(getDatabaseName(), countCommand, connection)
113+
executeCommand(getDatabaseName(), countCommand, getServerApi(), connection)
113114

114115
then:
115116
thrown(MongoSocketReadTimeoutException)

driver-core/src/test/unit/com/mongodb/internal/connection/DefaultConnectionPoolSpecification.groovy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DefaultConnectionPoolSpecification extends Specification {
5050
given:
5151
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
5252
builder().maxSize(1).build())
53-
pool.start();
53+
pool.start()
5454

5555
expect:
5656
pool.get() != null
@@ -60,7 +60,7 @@ class DefaultConnectionPoolSpecification extends Specification {
6060
given:
6161
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
6262
builder().maxSize(1).build())
63-
pool.start();
63+
pool.start()
6464

6565
when:
6666
pool.get().close()
@@ -74,7 +74,7 @@ class DefaultConnectionPoolSpecification extends Specification {
7474
given:
7575
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
7676
builder().maxSize(1).build())
77-
pool.start();
77+
pool.start()
7878

7979
when:
8080
pool.get().close()
@@ -87,7 +87,7 @@ class DefaultConnectionPoolSpecification extends Specification {
8787
given:
8888
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
8989
builder().maxSize(1).maxWaitTime(1, MILLISECONDS).build())
90-
pool.start();
90+
pool.start()
9191

9292
when:
9393
def first = pool.get()
@@ -106,7 +106,7 @@ class DefaultConnectionPoolSpecification extends Specification {
106106
given:
107107
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
108108
builder().maxSize(1).maxWaitTime(50, MILLISECONDS).build())
109-
pool.start();
109+
pool.start()
110110

111111
pool.get()
112112

@@ -124,7 +124,7 @@ class DefaultConnectionPoolSpecification extends Specification {
124124
given:
125125
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
126126
builder().maxSize(10).maintenanceInitialDelay(5, MINUTES).build())
127-
pool.start();
127+
pool.start()
128128

129129
when:
130130
pool.doMaintenance()
@@ -138,7 +138,7 @@ class DefaultConnectionPoolSpecification extends Specification {
138138
given:
139139
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
140140
builder().maxSize(10).minSize(5).maintenanceInitialDelay(5, MINUTES).build())
141-
pool.start();
141+
pool.start()
142142

143143
when: 'the maintenance tasks runs'
144144
pool.doMaintenance()
@@ -156,7 +156,7 @@ class DefaultConnectionPoolSpecification extends Specification {
156156
Thread.sleep(500)
157157

158158
then: 'it prunes the existing connections and again ensures the minimum size of the pool'
159-
connectionFactory.createdConnections.size() == 10
159+
connectionFactory.createdConnections.size() == 5
160160
connectionFactory.createdConnections.get(0).opened() // if the first one is opened, they all should be
161161
}
162162

driver-sync/src/test/functional/com/mongodb/client/ClientSideEncryptionBsonSizeLimitsSpecification.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ import static util.JsonPoweredTestHelper.getTestDocument
3939

4040
class ClientSideEncryptionBsonSizeLimitsSpecification extends FunctionalSpecification {
4141

42-
private final String collectionName = 'ClientSideEncryptionBsonSizeLimitsSpecification'
42+
private final String collName = 'ClientSideEncryptionBsonSizeLimitsSpecification'
4343
private final MongoNamespace keyVaultNamespace = new MongoNamespace('test.datakeys')
4444
private final MongoNamespace autoEncryptingCollectionNamespace = new MongoNamespace(getDefaultDatabaseName(),
45-
collectionName)
45+
collName)
4646
private final MongoCollection dataKeyCollection = getMongoClient()
4747
.getDatabase(keyVaultNamespace.databaseName).getCollection(keyVaultNamespace.collectionName, BsonDocument)
4848
.withWriteConcern(WriteConcern.MAJORITY)

0 commit comments

Comments
 (0)