Skip to content

Commit be38fa3

Browse files
SattvikSattvik
Sattvik
authored and
Sattvik
committed
fix: working test parallelisation for in-memory
1 parent a874e15 commit be38fa3

File tree

286 files changed

+1136
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

286 files changed

+1136
-196
lines changed

.github/workflows/million-users-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
running-for: core
2929

30-
test:
30+
million-users-test:
3131
name: Million Users Test
3232
needs: dependency-branches
3333
# if: github.event_name != 'pull_request' || github.event.review.state == 'approved'
@@ -36,7 +36,6 @@ jobs:
3636
matrix:
3737
plugin:
3838
- postgresql
39-
- mysql
4039

4140
runs-on: ubuntu-latest
4241
steps:

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ test {
114114
outputs.upToDateWhen { false }
115115
showStandardStreams = true
116116
}
117+
maxParallelForks = Runtime.runtime.availableProcessors() * 2
117118
}
118119

119120
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

src/main/java/io/supertokens/Main.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,16 @@ public void proceedToEnableFeatureFlag() {
364364
}
365365

366366
private void createDotStartedFileForThisProcess() throws IOException {
367+
String startedDir = ".started";
368+
if (isTesting) {
369+
startedDir = ".started" + System.getProperty("org.gradle.test.worker", "");
370+
}
367371
CoreConfig config = Config.getBaseConfig(this);
368372
String fileLocation = CLIOptions.get(this).getTempDirLocation() == null ? CLIOptions.get(this).getInstallationPath() : CLIOptions.get(this).getTempDirLocation();
369373
String fileName = OperatingSystem.getOS() == OperatingSystem.OS.WINDOWS
370-
? fileLocation + ".started\\" + config.getHost(this) + "-"
374+
? fileLocation + startedDir + "\\" + config.getHost(this) + "-"
371375
+ config.getPort(this)
372-
: fileLocation + ".started/" + config.getHost(this) + "-"
376+
: fileLocation + startedDir + "/" + config.getHost(this) + "-"
373377
+ config.getPort(this);
374378
File dotStarted = new File(fileName);
375379
if (!dotStarted.exists()) {

src/main/java/io/supertokens/config/Config.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ public static JsonObject getBaseConfigAsJsonObject(Main main) throws IOException
9595
}
9696

9797
private static String getConfigFilePath(Main main) {
98+
String configFile = "config.yaml";
99+
if (Main.isTesting) {
100+
String workerId = System.getProperty("org.gradle.test.worker", "");
101+
configFile = "config" + workerId + ".yaml";
102+
}
98103
return CLIOptions.get(main).getConfigFilePath() == null
99-
? CLIOptions.get(main).getInstallationPath() + "config.yaml"
104+
? CLIOptions.get(main).getInstallationPath() + configFile
100105
: CLIOptions.get(main).getConfigFilePath();
101106
}
102107

src/test/java/io/supertokens/test/APIKeysTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class APIKeysTest {
4949
@Rule
5050
public TestRule watchman = Utils.getOnFailure();
5151

52+
@Rule
53+
public TestRule retryFlaky = Utils.retryFlakyTest();
54+
5255
@AfterClass
5356
public static void afterTesting() {
5457
Utils.afterTesting();
@@ -498,6 +501,9 @@ private static <T> T sendJsonRequest(Main main, String url, JsonElement requestB
498501
int connectionTimeoutMS, int readTimeoutMS, String method,
499502
Map<String, String> headers) throws IOException,
500503
io.supertokens.test.httpRequest.HttpResponseException {
504+
if (HttpRequestForTesting.corePort != null) {
505+
url = url.replace(":3567", ":" + HttpRequestForTesting.corePort);
506+
}
501507
URL obj = getURL(main, "", url);
502508
InputStream inputStream = null;
503509
HttpURLConnection con = null;

src/test/java/io/supertokens/test/APITestsWithTrailingSlash.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class APITestsWithTrailingSlash {
3535
@Rule
3636
public TestRule watchman = Utils.getOnFailure();
3737

38+
@Rule
39+
public TestRule retryFlaky = Utils.retryFlakyTest();
40+
3841
@AfterClass
3942
public static void afterTesting() {
4043
Utils.afterTesting();

src/test/java/io/supertokens/test/ActiveUsersTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class ActiveUsersTest {
2929
@Rule
3030
public TestRule watchman = Utils.getOnFailure();
3131

32+
@Rule
33+
public TestRule retryFlaky = Utils.retryFlakyTest();
34+
3235
@AfterClass
3336
public static void afterTesting() {
3437
Utils.afterTesting();

src/test/java/io/supertokens/test/ApiVersionAPITest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class ApiVersionAPITest {
4747
@Rule
4848
public TestRule watchman = Utils.getOnFailure();
4949

50+
@Rule
51+
public TestRule retryFlaky = Utils.retryFlakyTest();
52+
5053
@AfterClass
5154
public static void afterTesting() {
5255
Utils.afterTesting();

src/test/java/io/supertokens/test/AuthRecipeAPITest2_10.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class AuthRecipeAPITest2_10 {
3838
@Rule
3939
public TestRule watchman = Utils.getOnFailure();
4040

41+
@Rule
42+
public TestRule retryFlaky = Utils.retryFlakyTest();
43+
4144
@AfterClass
4245
public static void afterTesting() {
4346
Utils.afterTesting();

src/test/java/io/supertokens/test/AuthRecipeAPITest2_8.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class AuthRecipeAPITest2_8 {
3636
@Rule
3737
public TestRule watchman = Utils.getOnFailure();
3838

39+
@Rule
40+
public TestRule retryFlaky = Utils.retryFlakyTest();
41+
3942
@AfterClass
4043
public static void afterTesting() {
4144
Utils.afterTesting();

src/test/java/io/supertokens/test/AuthRecipeTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class AuthRecipeTest {
5454
@Rule
5555
public TestRule watchman = Utils.getOnFailure();
5656

57+
@Rule
58+
public TestRule retryFlaky = Utils.retryFlakyTest();
59+
5760
@AfterClass
5861
public static void afterTesting() {
5962
Utils.afterTesting();

src/test/java/io/supertokens/test/AuthRecipesParallelTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class AuthRecipesParallelTest {
4141
@Rule
4242
public TestRule watchman = Utils.getOnFailure();
4343

44+
@Rule
45+
public TestRule retryFlaky = Utils.retryFlakyTest();
46+
4447
@AfterClass
4548
public static void afterTesting() {
4649
Utils.afterTesting();

src/test/java/io/supertokens/test/CDIVersionTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class CDIVersionTest {
5151
@Rule
5252
public TestRule watchman = Utils.getOnFailure();
5353

54+
@Rule
55+
public TestRule retryFlaky = Utils.retryFlakyTest();
56+
5457
@AfterClass
5558
public static void afterTesting() {
5659
Utils.afterTesting();
@@ -313,7 +316,7 @@ public void testJWKSEndpointWorksInAllCases() throws Exception {
313316
{
314317
// check regular output
315318
JsonObject response = HttpRequest.sendGETRequest(process.getProcess(), "",
316-
"http://localhost:3567/.well-known/jwks.json", null,
319+
"http://localhost:" + HttpRequestForTesting.corePort + "/.well-known/jwks.json", null,
317320
1000, 1000, null);
318321

319322
assertEquals(response.entrySet().size(), 1);
@@ -348,7 +351,7 @@ public void testJWKSEndpointWorksInAllCases() throws Exception {
348351
{
349352
// check regular output
350353
JsonObject response = HttpRequest.sendGETRequest(process.getProcess(), "",
351-
"http://localhost:3567/.well-known/jwks.json", null,
354+
"http://localhost:" + HttpRequestForTesting.corePort + "/.well-known/jwks.json", null,
352355
1000, 1000, null);
353356

354357
assertEquals(response.entrySet().size(), 1);

src/test/java/io/supertokens/test/CLIOptionsTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.supertokens.output.Logging;
2424
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
2525
import io.supertokens.test.TestingProcessManager.TestingProcess;
26+
import io.supertokens.test.httpRequest.HttpRequestForTesting;
2627
import org.junit.AfterClass;
2728
import org.junit.Before;
2829
import org.junit.Rule;
@@ -41,6 +42,9 @@ public class CLIOptionsTest {
4142
@Rule
4243
public TestRule watchman = Utils.getOnFailure();
4344

45+
@Rule
46+
public TestRule retryFlaky = Utils.retryFlakyTest();
47+
4448
@AfterClass
4549
public static void afterTesting() {
4650
Utils.afterTesting();
@@ -102,16 +106,16 @@ public void cli2ArgsTest() throws Exception {
102106

103107
@Test
104108
public void testMultipleInstancesAtTheSameTime() throws Exception {
105-
String[] args = {"../"};
109+
String[] args = {"../", "port=3567"};
106110

107111
try {
108112
// Create 2 custom config files
109-
ProcessBuilder pb = new ProcessBuilder("cp", "config.yaml", "temp/new1Config.yaml");
113+
ProcessBuilder pb = new ProcessBuilder("cp", "temp/config.yaml", "temp/new1Config.yaml");
110114
pb.directory(new File(args[0]));
111115
Process p1 = pb.start();
112116
p1.waitFor();
113117

114-
pb = new ProcessBuilder("cp", "config.yaml", "temp/new2Config.yaml");
118+
pb = new ProcessBuilder("cp", "temp/config.yaml", "temp/new2Config.yaml");
115119
pb.directory(new File(args[0]));
116120
p1 = pb.start();
117121
p1.waitFor();
@@ -295,24 +299,25 @@ public void cli2TempLocationTest() throws Exception {
295299
TestingProcess process = TestingProcessManager.startIsolatedProcess(args);
296300
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STARTED));
297301

302+
int port = HttpRequestForTesting.corePort;
303+
298304
assertEquals(Config.getConfig(process.getProcess()).getHost(process.getProcess()), "localhost");
299-
assertEquals(Config.getConfig(process.getProcess()).getPort(process.getProcess()), 3567);
305+
assertEquals(Config.getConfig(process.getProcess()).getPort(process.getProcess()), port);
300306

301307
process.kill();
302308
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED));
303309

304310
//process starts with tempDirLocation param too.
305-
args = new String[]{"../", "tempDirLocation=" + new File("../tempDir/").getAbsolutePath()};
311+
args = new String[]{"../", "tempDirLocation=" + new File("../tempDir/").getAbsolutePath(), "port="+port};
306312

307313
process = TestingProcessManager.startIsolatedProcess(args);
308314
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STARTED));
309315

310316
assertEquals(Config.getConfig(process.getProcess()).getHost(process.getProcess()), "localhost");
311-
assertEquals(Config.getConfig(process.getProcess()).getPort(process.getProcess()), 3567);
317+
assertEquals(Config.getConfig(process.getProcess()).getPort(process.getProcess()), port);
312318

313319
process.kill();
314320
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED));
315-
316321
}
317322

318323
}

src/test/java/io/supertokens/test/ConfigAPITest2_7.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class ConfigAPITest2_7 {
4040
@Rule
4141
public TestRule watchman = Utils.getOnFailure();
4242

43+
@Rule
44+
public TestRule retryFlaky = Utils.retryFlakyTest();
45+
4346
@AfterClass
4447
public static void afterTesting() {
4548
Utils.afterTesting();
@@ -59,7 +62,7 @@ public void inputErrorConfigAPITest() throws Exception {
5962

6063
// null for parameters
6164
try {
62-
HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:3567/config", null, 1000, 1000,
65+
HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:" + HttpRequestForTesting.corePort + "/config", null, 1000, 1000,
6366
null);
6467
fail();
6568
} catch (HttpResponseException e) {
@@ -72,7 +75,7 @@ public void inputErrorConfigAPITest() throws Exception {
7275
try {
7376
HashMap<String, String> map = new HashMap<>();
7477
map.put("pd", ProcessHandle.current().pid() + "");
75-
HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:3567/config", map, 1000, 1000, null);
78+
HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:" + HttpRequestForTesting.corePort + "/config", map, 1000, 1000, null);
7679
fail();
7780
} catch (HttpResponseException e) {
7881
assertTrue(e.getMessage()
@@ -148,11 +151,14 @@ public void testCustomConfigPath() throws Exception {
148151
@Test
149152
public void testVersion2TestCustomConfigPath() throws Exception {
150153
String path = new File("../temp/config.yaml").getAbsolutePath();
151-
String[] args = {"../", "configFile=" + path};
154+
int port = TestingProcessManager.getFreePort();
155+
String[] args = {"../", "configFile=" + path, "port="+port};
152156

153157
TestingProcessManager.TestingProcess process = TestingProcessManager.startIsolatedProcess(args);
154158
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
155159

160+
HttpRequestForTesting.corePort = port;
161+
156162
// map to store pid as parameter
157163
Map<String, String> map = new HashMap<>();
158164
map.put("pid", ProcessHandle.current().pid() + "");
@@ -188,7 +194,7 @@ public void outputPossibilitiesConfigAPITest() throws Exception {
188194
map.put("pid", ProcessHandle.current().pid() + "");
189195

190196
// check regular output
191-
JsonObject response = HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:3567/config", map,
197+
JsonObject response = HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:" + HttpRequestForTesting.corePort + "/config", map,
192198
1000, 1000, null);
193199

194200
assertEquals(response.get("status").getAsString(), "OK");
@@ -199,7 +205,7 @@ public void outputPossibilitiesConfigAPITest() throws Exception {
199205
map = new HashMap<>();
200206
map.put("pid", "-1");
201207

202-
response = HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:3567/config", map, 1000, 1000,
208+
response = HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:" + HttpRequestForTesting.corePort + "/config", map, 1000, 1000,
203209
null);
204210

205211
assertEquals(response.get("status").getAsString(), "NOT_ALLOWED");

src/test/java/io/supertokens/test/ConfigTest2_21.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class ConfigTest2_21 {
3232
@Rule
3333
public TestRule watchman = Utils.getOnFailure();
3434

35+
@Rule
36+
public TestRule retryFlaky = Utils.retryFlakyTest();
37+
3538
@AfterClass
3639
public static void afterTesting() {
3740
Utils.afterTesting();

src/test/java/io/supertokens/test/ConfigTest2_6.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.supertokens.config.CoreConfig;
2626
import io.supertokens.config.CoreConfigTestContent;
2727
import io.supertokens.test.TestingProcessManager.TestingProcess;
28+
import io.supertokens.test.httpRequest.HttpRequestForTesting;
2829
import org.junit.*;
2930
import org.junit.rules.TestRule;
3031

@@ -40,6 +41,9 @@ public class ConfigTest2_6 {
4041
@Rule
4142
public TestRule watchman = Utils.getOnFailure();
4243

44+
@Rule
45+
public TestRule retryFlaky = Utils.retryFlakyTest();
46+
4347
@AfterClass
4448
public static void afterTesting() {
4549
Utils.afterTesting();
@@ -194,7 +198,8 @@ public void testThatNonTestingConfigValuesThrowErrors() throws Exception {
194198

195199
@Test
196200
public void testThatMissingConfigFileThrowsError() throws Exception {
197-
String[] args = {"../"};
201+
String configFile = new File(new File(".").getAbsoluteFile().getParentFile().getParentFile().getPath(), "config.yaml").getAbsolutePath();
202+
String[] args = {"../", "configFile=" + configFile};
198203

199204
ProcessBuilder pb = new ProcessBuilder("rm", "config.yaml");
200205
pb.directory(new File(args[0]));
@@ -205,7 +210,7 @@ public void testThatMissingConfigFileThrowsError() throws Exception {
205210
ProcessState.EventAndException e = process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.INIT_FAILURE);
206211
assertNotNull(e);
207212
assertEquals(e.exception.getMessage(),
208-
"../config.yaml (No such file or directory)");
213+
configFile + " (No such file or directory)");
209214

210215
process.kill();
211216
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED));
@@ -262,7 +267,6 @@ private static void checkConfigValues(CoreConfig config, TestingProcess process,
262267
config.getAccessTokenDynamicSigningKeyUpdateIntervalInMillis(), 7 * 24 * 60 * 60 * 1000);
263268

264269
assertEquals(config.getHost(process.getProcess()), "localhost");
265-
assertEquals(config.getPort(process.getProcess()), 3567);
266270
assertNull(config.getAPIKeys());
267271
assertEquals(10, config.getMaxThreadPoolSize());
268272
assertFalse(config.getHttpsEnabled());

src/test/java/io/supertokens/test/CronjobTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ public int getCount() {
362362
@Rule
363363
public TestRule watchman = Utils.getOnFailure();
364364

365+
@Rule
366+
public TestRule retryFlaky = Utils.retryFlakyTest();
367+
365368
@AfterClass
366369
public static void afterTesting() {
367370
Utils.afterTesting();

0 commit comments

Comments
 (0)