Skip to content

Commit 9e11ad2

Browse files
authored
test: Add delay to flake Active users tests (#604)
1 parent 833c7d3 commit 9e11ad2

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void updateAndCountUserLastActiveTest() throws Exception {
5555

5656
assert ActiveUsers.countUsersActiveSince(main, now) == 2;
5757

58-
Thread.sleep(100);
58+
Thread.sleep(1);
5959

6060
long now2 = System.currentTimeMillis();
6161

src/test/java/io/supertokens/test/emailpassword/api/SignInAPITest2_7.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public void testGoodInput() throws Exception {
140140
responseBody.addProperty("email", "[email protected]");
141141
responseBody.addProperty("password", "validPass123");
142142

143+
Thread.sleep(1); // add a small delay to ensure a unique timestamp
143144
long beforeSignIn = System.currentTimeMillis();
144145

145146
JsonObject signInResponse = HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "",

src/test/java/io/supertokens/test/emailpassword/api/SignUpAPITest2_7.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void testBadInput() throws Exception {
7070
return;
7171
}
7272

73-
long beforeTestTs = System.currentTimeMillis();
73+
long startTs = System.currentTimeMillis();
7474

7575
{
7676
try {
@@ -111,7 +111,7 @@ public void testBadInput() throws Exception {
111111
}
112112
}
113113

114-
int activeUsers = ActiveUsers.countUsersActiveSince(process.getProcess(), beforeTestTs);
114+
int activeUsers = ActiveUsers.countUsersActiveSince(process.getProcess(), startTs);
115115
assert (activeUsers == 0);
116116

117117
process.kill();
@@ -130,7 +130,7 @@ public void testGoodInput() throws Exception {
130130
return;
131131
}
132132

133-
long beforeSignUpTs = System.currentTimeMillis();
133+
long startTS = System.currentTimeMillis();
134134

135135
JsonObject signUpResponse = Utils.signUpRequest_2_5(process, "[email protected]", "validPass123");
136136
assertEquals(signUpResponse.get("status").getAsString(), "OK");
@@ -140,7 +140,7 @@ public void testGoodInput() throws Exception {
140140
assertEquals(signUpUser.get("email").getAsString(), "[email protected]");
141141
assertNotNull(signUpUser.get("id"));
142142

143-
int activeUsers = ActiveUsers.countUsersActiveSince(process.getProcess(), beforeSignUpTs);
143+
int activeUsers = ActiveUsers.countUsersActiveSince(process.getProcess(), startTS);
144144
assert (activeUsers == 1);
145145

146146
UserInfo user = StorageLayer.getEmailPasswordStorage(process.getProcess())

src/test/java/io/supertokens/test/session/api/RefreshSessionAPITest2_7.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ public void activeUsersTest() throws Exception {
439439
request.add("userDataInDatabase", userDataInDatabase);
440440
request.addProperty("enableAntiCsrf", false);
441441

442+
Thread.sleep(1); // Ensures a unique timestamp
442443
long startTs = System.currentTimeMillis();
443444

444445
JsonObject sessionInfo = HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "",
@@ -452,6 +453,7 @@ public void activeUsersTest() throws Exception {
452453
sessionInfo.get("refreshToken").getAsJsonObject().get("token").getAsString());
453454
sessionRefreshBody.addProperty("enableAntiCsrf", false);
454455

456+
Thread.sleep(1); // ensures a unique timestamp
455457
long afterSessionCreateTs = System.currentTimeMillis();
456458

457459
JsonObject sessionRefreshResponse = HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "",

src/test/java/io/supertokens/test/session/api/SessionRemoveAPITest2_7.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void activeUsersTest() throws Exception {
9393
assertEquals(s2Info.get("status").getAsString(), "OK");
9494

9595
// remove s2 and make sure they are returned
96-
96+
Thread.sleep(1); // ensures a unique timestamp
9797
long checkpoint1 = System.currentTimeMillis();
9898

9999
JsonObject sessionRemoveBody = new JsonObject();
@@ -135,6 +135,7 @@ public void activeUsersTest() throws Exception {
135135
"session");
136136
assertEquals(session2Info.get("status").getAsString(), "OK");
137137

138+
Thread.sleep(1); // ensures a unique timestamp
138139
long checkpoint1 = System.currentTimeMillis();
139140

140141
// remove session using user id

0 commit comments

Comments
 (0)