Skip to content

Commit

Permalink
Build: Fix slow tests (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza authored Aug 10, 2021
1 parent e55594d commit fb6388c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ configure(javaCodeCheckedProjects) {
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation('org.junit.vintage:junit-vintage-engine')

testImplementation platform('org.spockframework:spock-bom:2.0-M3-groovy-2.5')
testImplementation platform('org.spockframework:spock-bom:2.0-groovy-2.5')
testImplementation 'org.spockframework:spock-core'
testImplementation 'org.spockframework:spock-junit4'
testImplementation("org.mockito:mockito-core:3.8.0")
Expand Down Expand Up @@ -274,10 +274,17 @@ configure(javaCodeCheckedProjects) {
}

task testSlowOnly(type: Test) {
dependsOn('testSlowGroovy')
useJUnitPlatform {
includeEngines('junit-jupiter', 'junit-vintage', 'spock')
includeEngines('junit-jupiter', 'junit-vintage')
includeTags('Slow')
}
}

task testSlowGroovy(type: Test) {
useJUnitPlatform {
includeEngines( 'spock')
}
systemProperty('spock.configuration', "${configDir}/spock/OnlySlow.groovy")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.mongodb.MongoSocketReadTimeoutException
import com.mongodb.OperationFunctionalSpecification
import com.mongodb.ServerAddress
import com.mongodb.connection.AsynchronousSocketChannelStreamFactory
import com.mongodb.connection.ClusterConnectionMode
import com.mongodb.connection.ClusterId
import com.mongodb.connection.ServerId
import com.mongodb.connection.SocketSettings
Expand All @@ -39,7 +40,6 @@ import static com.mongodb.ClusterFixture.getServerApi
import static com.mongodb.ClusterFixture.getSslSettings
import static com.mongodb.internal.connection.CommandHelper.executeCommand

@IgnoreIf({ System.getProperty('ignoreSlowUnitTests') == 'true' })
@Slow
class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification {

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

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

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

when:
executeCommand(getDatabaseName(), countCommand, connection)
executeCommand(getDatabaseName(), countCommand, getServerApi(), connection)

then:
thrown(MongoSocketReadTimeoutException)
Expand All @@ -85,9 +85,10 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification

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

when:
connection.open()
Expand All @@ -99,17 +100,17 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification

def 'should throw a MongoSocketReadTimeoutException with the Netty stream'() {
given:
def connection = new InternalStreamConnectionFactory(
new NettyStreamFactory(readSocketSettings, getSslSettings()), getCredentialWithCache(), null, null, [], getServerApi(),
).create(new ServerId(new ClusterId(), getPrimary()), connectionGeneration)
def connection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE,
new NettyStreamFactory(readSocketSettings, getSslSettings()), getCredentialWithCache(), null, null,
[], null, getServerApi()).create(new ServerId(new ClusterId(), getPrimary()))
connection.open()

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

when:
executeCommand(getDatabaseName(), countCommand, connection)
executeCommand(getDatabaseName(), countCommand, getServerApi(), connection)

then:
thrown(MongoSocketReadTimeoutException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DefaultConnectionPoolSpecification extends Specification {
given:
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
builder().maxSize(1).build())
pool.start();
pool.start()

expect:
pool.get() != null
Expand All @@ -60,7 +60,7 @@ class DefaultConnectionPoolSpecification extends Specification {
given:
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
builder().maxSize(1).build())
pool.start();
pool.start()

when:
pool.get().close()
Expand All @@ -74,7 +74,7 @@ class DefaultConnectionPoolSpecification extends Specification {
given:
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
builder().maxSize(1).build())
pool.start();
pool.start()

when:
pool.get().close()
Expand All @@ -87,7 +87,7 @@ class DefaultConnectionPoolSpecification extends Specification {
given:
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
builder().maxSize(1).maxWaitTime(1, MILLISECONDS).build())
pool.start();
pool.start()

when:
def first = pool.get()
Expand All @@ -106,7 +106,7 @@ class DefaultConnectionPoolSpecification extends Specification {
given:
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
builder().maxSize(1).maxWaitTime(50, MILLISECONDS).build())
pool.start();
pool.start()

pool.get()

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

when:
pool.doMaintenance()
Expand All @@ -138,7 +138,7 @@ class DefaultConnectionPoolSpecification extends Specification {
given:
pool = new DefaultConnectionPool(SERVER_ID, connectionFactory,
builder().maxSize(10).minSize(5).maintenanceInitialDelay(5, MINUTES).build())
pool.start();
pool.start()

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import static util.JsonPoweredTestHelper.getTestDocument

class ClientSideEncryptionBsonSizeLimitsSpecification extends FunctionalSpecification {

private final String collectionName = 'ClientSideEncryptionBsonSizeLimitsSpecification'
private final String collName = 'ClientSideEncryptionBsonSizeLimitsSpecification'
private final MongoNamespace keyVaultNamespace = new MongoNamespace('test.datakeys')
private final MongoNamespace autoEncryptingCollectionNamespace = new MongoNamespace(getDefaultDatabaseName(),
collectionName)
collName)
private final MongoCollection dataKeyCollection = getMongoClient()
.getDatabase(keyVaultNamespace.databaseName).getCollection(keyVaultNamespace.collectionName, BsonDocument)
.withWriteConcern(WriteConcern.MAJORITY)
Expand Down

0 comments on commit fb6388c

Please sign in to comment.