2727import io .supertokens .emailpassword .EmailPassword ;
2828import io .supertokens .emailpassword .ParsedFirebaseSCryptResponse ;
2929import io .supertokens .featureflag .EE_FEATURES ;
30+ import io .supertokens .featureflag .FeatureFlag ;
3031import io .supertokens .featureflag .FeatureFlagTestContent ;
3132import io .supertokens .passwordless .Passwordless ;
33+ import io .supertokens .pluginInterface .RECIPE_ID ;
34+ import io .supertokens .pluginInterface .Storage ;
3235import io .supertokens .pluginInterface .authRecipe .AuthRecipeUserInfo ;
3336import io .supertokens .pluginInterface .authRecipe .LoginMethod ;
3437import io .supertokens .pluginInterface .authRecipe .sqlStorage .AuthRecipeSQLStorage ;
3942import io .supertokens .pluginInterface .thirdparty .sqlStorage .ThirdPartySQLStorage ;
4043import io .supertokens .session .Session ;
4144import io .supertokens .session .info .SessionInformationHolder ;
45+ import io .supertokens .storage .postgresql .Start ;
4246import io .supertokens .storage .postgresql .test .httpRequest .HttpRequestForTesting ;
4347import io .supertokens .storageLayer .StorageLayer ;
4448import io .supertokens .thirdparty .ThirdParty ;
@@ -386,6 +390,30 @@ private void createSessions(Main main) throws Exception {
386390 es .awaitTermination (10 , TimeUnit .MINUTES );
387391 }
388392
393+ private void createActiveUserEntries (Main main ) throws Exception {
394+ System .out .println ("Creating active user entries..." );
395+
396+ ExecutorService es = Executors .newFixedThreadPool (NUM_THREADS );
397+
398+ for (String userId : allPrimaryUserIds ) {
399+ String finalUserId = userId ;
400+ es .execute (() -> {
401+ try {
402+ Storage storage = StorageLayer .getBaseStorage (main );
403+ Start start = (Start ) storage ;
404+
405+ start .updateLastActive (new AppIdentifier (null , null ), finalUserId , System .currentTimeMillis () - new Random ().nextInt (1000 * 3600 * 24 * 60 ));
406+
407+ } catch (Exception e ) {
408+ throw new RuntimeException (e );
409+ }
410+ });
411+ }
412+
413+ es .shutdown ();
414+ es .awaitTermination (10 , TimeUnit .MINUTES );
415+ }
416+
389417 @ Test
390418 public void testCreatingOneMillionUsers () throws Exception {
391419 if (System .getenv ("ONE_MILLION_USERS_TEST" ) == null ) {
@@ -400,7 +428,7 @@ public void testCreatingOneMillionUsers() throws Exception {
400428
401429 FeatureFlagTestContent .getInstance (process .getProcess ())
402430 .setKeyValue (FeatureFlagTestContent .ENABLED_FEATURES , new EE_FEATURES []{
403- EE_FEATURES .ACCOUNT_LINKING , EE_FEATURES .MULTI_TENANCY });
431+ EE_FEATURES .ACCOUNT_LINKING , EE_FEATURES .MULTI_TENANCY , EE_FEATURES . MFA , EE_FEATURES . DASHBOARD_LOGIN });
404432 process .startProcess ();
405433 assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STARTED ));
406434
@@ -445,6 +473,13 @@ public void testCreatingOneMillionUsers() throws Exception {
445473 System .out .println ("Time taken to create sessions: " + ((en - st ) / 1000 ) + " sec" );
446474 }
447475
476+ {
477+ long st = System .currentTimeMillis ();
478+ createActiveUserEntries (process .getProcess ());
479+ long en = System .currentTimeMillis ();
480+ System .out .println ("Time taken to create active user entries: " + ((en - st ) / 1000 ) + " sec" );
481+ }
482+
448483 sanityCheckAPIs (process .getProcess ());
449484 allUserIds .clear ();
450485 allPrimaryUserIds .clear ();
@@ -466,7 +501,7 @@ public void testCreatingOneMillionUsers() throws Exception {
466501
467502 FeatureFlagTestContent .getInstance (process .getProcess ())
468503 .setKeyValue (FeatureFlagTestContent .ENABLED_FEATURES , new EE_FEATURES []{
469- EE_FEATURES .ACCOUNT_LINKING , EE_FEATURES .MULTI_TENANCY });
504+ EE_FEATURES .ACCOUNT_LINKING , EE_FEATURES .MULTI_TENANCY , EE_FEATURES . MFA , EE_FEATURES . DASHBOARD_LOGIN });
470505 process .startProcess ();
471506 assertNotNull (process .checkOrWaitForEvent (ProcessState .PROCESS_STATE .STARTED ));
472507
@@ -888,6 +923,36 @@ private void measureOperations(Main main) throws Exception {
888923 return null ;
889924 });
890925 System .out .println ("Update user metadata " + time );
926+ assert time < 3000 ;
927+ }
928+
929+ { // measure user counting
930+ long time = measureTime (() -> {
931+ try {
932+ AuthRecipe .getUsersCount (main , null );
933+ AuthRecipe .getUsersCount (main , new RECIPE_ID []{RECIPE_ID .EMAIL_PASSWORD });
934+ AuthRecipe .getUsersCount (main , new RECIPE_ID []{RECIPE_ID .EMAIL_PASSWORD , RECIPE_ID .THIRD_PARTY });
935+ } catch (Exception e ) {
936+ errorCount .incrementAndGet ();
937+ throw new RuntimeException (e );
938+ }
939+ return null ;
940+ });
941+ System .out .println ("User counting: " + time );
942+ assert time < 3000 ;
943+ }
944+ { // measure telemetry
945+ long time = measureTime (() -> {
946+ try {
947+ FeatureFlag .getInstance (main ).getPaidFeatureStats ();
948+ } catch (Exception e ) {
949+ errorCount .incrementAndGet ();
950+ throw new RuntimeException (e );
951+ }
952+ return null ;
953+ });
954+ System .out .println ("Telemetry: " + time );
955+ assert time < 3000 ;
891956 }
892957
893958 assertEquals (0 , errorCount .get ());
0 commit comments