-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for active users update across different API calls (#586
) * test: Add tests for active users update across different API calls * fix: Suppress usermapping exceptions for active users monitoring (#587)
- Loading branch information
Showing
15 changed files
with
281 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.supertokens.test; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
|
||
import io.supertokens.pluginInterface.STORAGE_TYPE; | ||
import io.supertokens.storageLayer.StorageLayer; | ||
import io.supertokens.ActiveUsers; | ||
import io.supertokens.Main; | ||
import io.supertokens.ProcessState; | ||
|
||
public class ActiveUsersTest { | ||
|
||
@Rule | ||
public TestRule watchman = Utils.getOnFailure(); | ||
|
||
@AfterClass | ||
public static void afterTesting() { | ||
Utils.afterTesting(); | ||
} | ||
|
||
@Before | ||
public void beforeEach() { | ||
Utils.reset(); | ||
} | ||
|
||
@Test | ||
public void updateAndCountUserLastActiveTest() throws Exception { | ||
String[] args = { "../" }; | ||
|
||
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); | ||
|
||
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { | ||
assert (false); | ||
} | ||
|
||
Main main = process.getProcess(); | ||
long now = System.currentTimeMillis(); | ||
|
||
assert ActiveUsers.countUsersActiveSince(main, now) == 0; | ||
|
||
ActiveUsers.updateLastActive(main, "user1"); | ||
ActiveUsers.updateLastActive(main, "user2"); | ||
|
||
assert ActiveUsers.countUsersActiveSince(main, now) == 2; | ||
|
||
long now2 = System.currentTimeMillis(); | ||
|
||
ActiveUsers.updateLastActive(main, "user1"); | ||
|
||
assert ActiveUsers.countUsersActiveSince(main, now) == 2; // user1 just got updated | ||
assert ActiveUsers.countUsersActiveSince(main, now2) == 1; // only user1 is counted | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.