Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Fix slow tests #773

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the spock test dependency

useJUnitPlatform {
includeEngines('junit-jupiter', 'junit-vintage', 'spock')
includeEngines('junit-jupiter', 'junit-vintage')
includeTags('Slow')
}
}

task testSlowGroovy(type: Test) {
Copy link
Member Author

@rozza rozza Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to create a custom task just for the groovy tests and that fixes the issue ?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats's what seem to be suggested as the solution, which is unfortunate: spockframework/spock#1288 (comment).

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' })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a legacy system property

@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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are just to bring the code up to date.

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a test bug.

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'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side effect of Spock dependency update? Theres a getCollectionName method in the FunctionalSpecification and spock complained they clashed.

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