-
-
Notifications
You must be signed in to change notification settings - Fork 102
Enable tests to run in parallel by default #3895
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
base: main
Are you sure you want to change the base?
Changes from all commits
f363428
2376022
cdec6bb
44d0c39
be84308
1ba12c7
1d0342e
6488c38
e8375db
a41ff64
ca38e62
703eba0
a8f9dcd
ddc6dbf
99aa587
c454c1c
c826fe5
16af5f2
00afff9
64e2abd
8280281
3b6fd79
6a23fdf
9dff309
0762c40
91407e5
2c5f0f0
6275cb2
69e265d
50ec604
28f6a6e
87e67e6
2f591d6
3266b9b
7e9e0c6
ce445f6
f7b0fb0
34c5150
ef55e43
14fa415
8e79172
f8f942c
867ccca
f58e1ad
b09a93f
136f775
05758f2
24af8f3
2ea2ee0
3b6117c
7705b9e
15b72ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,8 @@ | |
|
|
||
| import java.io.File; | ||
| import java.util.Collection; | ||
| import java.util.EnumMap; | ||
| import java.util.Map; | ||
| import java.util.Random; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
|
|
@@ -43,10 +45,13 @@ | |
| import static org.assertj.core.api.Assertions.fail; | ||
|
|
||
| public abstract class TestHelper { | ||
| protected static final int PARALLEL_LEVEL = 4; | ||
| protected static final int PARALLEL_LEVEL = 4; | ||
| protected final DatabaseFactory factory; | ||
| protected Database database; | ||
| protected boolean autoStartTx = false; | ||
| protected boolean autoStartTx = false; | ||
|
|
||
| private static final Object ACTIVE_DB_LOCK = new Object(); | ||
| private Map<GlobalConfiguration, Object> configSnapshot; | ||
|
|
||
| public interface DatabaseTest<PAR> { | ||
| void call(PAR iArgument) throws Exception; | ||
|
|
@@ -158,6 +163,7 @@ protected void endTest() { | |
|
|
||
| @BeforeEach | ||
| public void beforeTest() { | ||
| configSnapshot = captureConfigSnapshot(); | ||
| GlobalConfiguration.SERVER_ROOT_PATH.setValue("./target"); | ||
| if (autoStartTx && !database.isTransactionActive()) | ||
| database.begin(); | ||
|
|
@@ -184,14 +190,28 @@ public void afterTest() { | |
|
|
||
| checkActiveDatabases(); | ||
| FileUtils.deleteRecursively(new File(getDatabasePath())); | ||
| GlobalConfiguration.resetAll(); | ||
| restoreConfigSnapshot(configSnapshot); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void endAllTests() { | ||
| GlobalConfiguration.resetAll(); | ||
| } | ||
|
|
||
| private static Map<GlobalConfiguration, Object> captureConfigSnapshot() { | ||
| final Map<GlobalConfiguration, Object> snapshot = new EnumMap<>(GlobalConfiguration.class); | ||
| for (final GlobalConfiguration v : GlobalConfiguration.values()) | ||
| snapshot.put(v, v.getValue()); | ||
| return snapshot; | ||
| } | ||
|
|
||
| private static void restoreConfigSnapshot(final Map<GlobalConfiguration, Object> snapshot) { | ||
| if (snapshot == null) | ||
| return; | ||
| for (final Map.Entry<GlobalConfiguration, Object> e : snapshot.entrySet()) | ||
| e.getKey().setValue(e.getValue()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restoring every configuration value after every test method is expensive, especially since final GlobalConfiguration config = e.getKey();
final Object value = e.getValue();
if (value != null && !value.equals(config.getValue()))
config.setValue(value); |
||
| } | ||
|
|
||
| protected String getPerformanceProfile() { | ||
| return "default"; | ||
| } | ||
|
|
@@ -227,15 +247,17 @@ protected void checkDatabaseIntegrity() { | |
| } | ||
|
|
||
| public static void checkActiveDatabases() { | ||
| final Collection<Database> activeDatabases = DatabaseFactory.getActiveDatabaseInstances(); | ||
| synchronized (ACTIVE_DB_LOCK) { | ||
| final Collection<Database> activeDatabases = DatabaseFactory.getActiveDatabaseInstances(); | ||
|
|
||
| if (!activeDatabases.isEmpty()) | ||
| LogManager.instance() | ||
| .log(TestHelper.class, Level.SEVERE, "Found active databases: " + activeDatabases + ". Forced closing..."); | ||
| if (!activeDatabases.isEmpty()) | ||
| LogManager.instance() | ||
| .log(TestHelper.class, Level.SEVERE, "Found active databases: " + activeDatabases + ". Forced closing..."); | ||
|
|
||
| for (final Database db : activeDatabases) | ||
| db.close(); | ||
| for (final Database db : activeDatabases) | ||
| db.close(); | ||
|
|
||
| assertThat(activeDatabases.isEmpty()).as("Found active databases: " + activeDatabases).isTrue(); | ||
| assertThat(activeDatabases.isEmpty()).as("Found active databases: " + activeDatabases).isTrue(); | ||
| } | ||
|
Comment on lines
+250
to
+261
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This synchronization only prevents multiple threads from executing the |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
captureConfigSnapshotis called before every test method, caching theGlobalConfiguration.values()array in a constant can avoid repeated array allocations.