Skip to content

Commit

Permalink
Build: split tests that need database from those that do not (#12123)
Browse files Browse the repository at this point in the history
Update adds a tag to tests that need a database. We then
split the build such that 'test' no longer runs these
tests, and 'testWithDatabase' does (and we add
'testAll' to test all)

This allows for './gradlew test' to no longer depend
on any running docker containers & faster game-headed
development.
  • Loading branch information
DanVanAtta authored Nov 24, 2023
1 parent 8fe64cb commit 70b40d0
Show file tree
Hide file tree
Showing 28 changed files with 107 additions and 5 deletions.
28 changes: 27 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,33 @@ subprojects {
}
}

// 'test' runs only the tests that do _not_ need a database
test {
useJUnitPlatform()
useJUnitPlatform() {
excludeTags 'RequiresDatabase'
}
}

// 'testWithDatabase' runs only the tests that need a database
tasks.register('testWithDatabase', Test) {
description = 'Runs integration tests.'
group = 'verification'

dependsOn(":spitfire-server:database:flywayMigrateLobbyDb")
dependsOn(":spitfire-server:database:flywayMigrateErrorReportDb")

useJUnitPlatform() {
includeTags 'RequiresDatabase'
}
}

// - 'testAll' runs all tests
task testAll {
dependsOn testWithDatabase
dependsOn test
}

// - 'check' should run ALL validations, tests, spotlessChecks, everything..
check.dependsOn testAll

}
15 changes: 14 additions & 1 deletion docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ IDEA should automatically find. Look in 'run configurations' to launch the game
./game-app/run/check
```

## Run Tests

```
./gradlew test
```

## Run Tests that need a running database

```
./gradlew testWithDatabase
```


## Run Formatting

We use 'google java format', be sure to install the plugin in your IDE to properly format
Expand Down Expand Up @@ -121,7 +134,7 @@ The deployment code is inside of the '[/infrastructure](./infrastructure)' folde
We use [ansible](https://www.ansible.com/) to execute deployments.

You can test out deployment code by first launching a virtual machine and then running a deployment
against that virtual machine. See '[infrastructure/vagrant/REAMDE.md](./infrastructure/vagrant/REAMDE.md)'
against that virtual machine. See '[infrastructure/vagrant/README.md](./infrastructure/vagrant/README.md)'
for more information.

# Pitfalls and Pain Points to be aware of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.triplea.test.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.Tag;

/**
* 'RequiresDatabase' means a database needs to be running (presumably on docker) for the test to
* pass. Tests annotated with 'RequiresDatabase' will not run with 'gradle test' task but will
* instead run with the 'check', 'testAll' or 'testWithDatabase' tasks.
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Tag("RequiresDatabase")
public @interface RequiresDatabase {}
1 change: 1 addition & 0 deletions servers/error-reporting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
testImplementation "com.github.database-rider:rider-junit5:$databaseRiderVersion"
testImplementation "io.dropwizard:dropwizard-testing:$dropwizardVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
testImplementation project(':lib:test-common')
testImplementation project(':servers:server-test-support')
testImplementation project(':spitfire-server:database-test-support')
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import org.triplea.http.client.error.report.ErrorReportClient;
import org.triplea.http.client.error.report.ErrorReportRequest;
import org.triplea.http.client.error.report.ErrorReportResponse;
import org.triplea.test.common.RequiresDatabase;

@ExtendWith(ErrorReportServerTestExtension.class)
// @ExtendWith(SpitfireDatabaseTestSupport.class)
// @ExtendWith(DBUnitExtension.class)
// @DataSet(value = ControllerIntegrationTest.DATA_SETS, useSequenceFiltering = false)
@RequiresDatabase
class ErrorReportControllerIntegrationTest {
private final ErrorReportClient client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import io.dropwizard.testing.DropwizardTestSupport;
import org.triplea.server.error.reporting.ErrorReportingConfiguration;
import org.triplea.server.error.reporting.ErrorReportingServer;
import org.triplea.test.common.RequiresDatabase;
import org.triplea.test.support.DropwizardServerExtension;

/**
* Use with {@code @ExtendWith(SpitfireServerTestExtension.class)} Tests extended with this
* extension will launch a drop wizard server when the test starts up. If a server is already
* running at the start of a test, it will be re-used.
*/
@RequiresDatabase
public class ErrorReportServerTestExtension
extends DropwizardServerExtension<ErrorReportingConfiguration> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.triplea.server.error.reporting.upload.ErrorReportingDao;
import org.triplea.server.error.reporting.upload.InsertHistoryRecordParams;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(ErrorReportingModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
final class ErrorReportingDaoTest {
private final ErrorReportingDao errorReportingDao;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import org.triplea.domain.data.ApiKey;
import org.triplea.domain.data.SystemIdLoader;
import org.triplea.http.client.LobbyHttpClientConfig;
import org.triplea.test.common.RequiresDatabase;

@ExtendWith(SpitfireServerTestExtension.class)
@ExtendWith(SpitfireDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@DataSet(value = ControllerIntegrationTest.DATA_SETS, useSequenceFiltering = false)
@RequiresDatabase
public abstract class ControllerIntegrationTest {

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class AccessLogDaoTest {
private static final String EMPTY_ACCESS_LOG =
"access_log/user_role.yml,access_log/lobby_user.yml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class GameHostingApiKeyDaoTest {

private final GameHostingApiKeyDao gameHostApiKeyDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.db.dao.user.role.UserRole;
import org.triplea.test.common.RequiresDatabase;

@DataSet(
value =
Expand All @@ -24,6 +25,7 @@
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class PlayerApiKeyDaoTest {

private static final int USER_ID = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class LobbyChatHistoryDaoTest {

private final LobbyChatHistoryDao lobbyChatHistoryDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import org.triplea.domain.data.ApiKey;
import org.triplea.http.client.lobby.game.lobby.watcher.ChatMessageUpload;
import org.triplea.http.client.lobby.game.lobby.watcher.LobbyGameListing;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class LobbyGameDaoTest {
private final LobbyGameDao lobbyGameDao;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@DataSet(value = "bad_words/bad_word.yml", useSequenceFiltering = false)
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class BadWordsDaoTest {
private static final List<String> expectedBadWords = List.of("aaa", "one", "two", "zzz");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@DataSet(
Expand All @@ -26,6 +27,7 @@
useSequenceFiltering = false)
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class ModeratorAuditHistoryDaoTest {

private static final int MODERATOR_ID = 900000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.db.dao.user.role.UserRole;
import org.triplea.test.common.RequiresDatabase;

@DataSet(
value = "moderators/user_role.yml, moderators/lobby_user.yml, moderators/access_log.yml",
useSequenceFiltering = false)
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class ModeratorsDaoTest {

private static final int NOT_MODERATOR_ID = 100000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@DataSet(
value =
Expand All @@ -24,6 +25,7 @@
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class GameChatHistoryDaoTest {
private static final String SIR_HOSTS_A_LOT = "sir_hosts_a_lot";
private static final String SIR_HOSTS_A_LITTLE = "sir_hosts_a_little";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class PlayerInfoForModeratorDaoTest {

private final PlayerInfoForModeratorDao playerInfoForModeratorDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@DataSet(
value =
Expand All @@ -21,6 +22,7 @@
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class TempPasswordDaoTest {

private static final String USERNAME = "username";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@DataSet(
cleanBefore = true,
value = "temp_password_history/sample.yml",
useSequenceFiltering = false)
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@RequiresDatabase
class TempPasswordHistoryDaoTest {

private static final String USERNAME = "username";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.db.dao.user.role.UserRole;
import org.triplea.db.dao.user.role.UserRoleLookup;
import org.triplea.test.common.RequiresDatabase;

@DataSet(value = "user/user_role.yml,user/lobby_user.yml", useSequenceFiltering = false)
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class UserJdbiDaoTest {

private static final int USER_ID = 900000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class UserBanDaoTest {
private final UserBanDao userBanDao;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@DataSet(value = "user_role/initial.yml", useSequenceFiltering = false)
@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class UserRoleDaoTest {

private final UserRoleDao userRoleDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class UsernameBanDaoTest {

private final UsernameBanDao usernameBanDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.triplea.db.LobbyModuleDatabaseTestSupport;
import org.triplea.test.common.RequiresDatabase;

@RequiredArgsConstructor
@ExtendWith(LobbyModuleDatabaseTestSupport.class)
@ExtendWith(DBUnitExtension.class)
@RequiresDatabase
class LobbyLoginMessageDaoTest {

private final LobbyLoginMessageDao lobbyLoginMessageDao;
Expand Down
Loading

0 comments on commit 70b40d0

Please sign in to comment.