Skip to content

Commit

Permalink
fix: add one million user test update
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 4, 2024
1 parent e6fb619 commit 70bc4b8
Showing 1 changed file with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import io.supertokens.emailpassword.EmailPassword;
import io.supertokens.emailpassword.ParsedFirebaseSCryptResponse;
import io.supertokens.featureflag.EE_FEATURES;
import io.supertokens.featureflag.FeatureFlag;
import io.supertokens.featureflag.FeatureFlagTestContent;
import io.supertokens.passwordless.Passwordless;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.authRecipe.LoginMethod;
import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage;
Expand All @@ -37,8 +39,10 @@
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.passwordless.sqlStorage.PasswordlessSQLStorage;
import io.supertokens.pluginInterface.thirdparty.sqlStorage.ThirdPartySQLStorage;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.session.Session;
import io.supertokens.session.info.SessionInformationHolder;
import io.supertokens.storage.mysql.Start;
import io.supertokens.storage.mysql.test.httpRequest.HttpRequestForTesting;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.thirdparty.ThirdParty;
Expand Down Expand Up @@ -394,10 +398,34 @@ private void createSessions(Main main) throws Exception {
es.awaitTermination(12, TimeUnit.MINUTES);
}

private void createActiveUserEntries(Main main) throws Exception {
System.out.println("Creating active user entries...");

ExecutorService es = Executors.newFixedThreadPool(NUM_THREADS);

for (String userId : allPrimaryUserIds) {
String finalUserId = userId;
es.execute(() -> {
try {
Storage storage = StorageLayer.getBaseStorage(main);
Start start = (Start) storage;

start.updateLastActive(new AppIdentifier(null, null), finalUserId, System.currentTimeMillis() - new Random().nextInt(1000 * 3600 * 24 * 60));

} catch (Exception e) {
throw new RuntimeException(e);
}
});
}

es.shutdown();
es.awaitTermination(10, TimeUnit.MINUTES);
}

@Test
public void testCreatingOneMillionUsers() throws Exception {
if (System.getenv("ONE_MILLION_USERS_TEST") == null) {
return;
// return;
}

String[] args = {"../"};
Expand All @@ -408,7 +436,7 @@ public void testCreatingOneMillionUsers() throws Exception {

FeatureFlagTestContent.getInstance(process.getProcess())
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{
EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY});
EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY, EE_FEATURES.MFA, EE_FEATURES.DASHBOARD_LOGIN});
process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

Expand Down Expand Up @@ -453,6 +481,13 @@ public void testCreatingOneMillionUsers() throws Exception {
System.out.println("Time taken to create sessions: " + ((en - st) / 1000) + " sec");
}

{
long st = System.currentTimeMillis();
createActiveUserEntries(process.getProcess());
long en = System.currentTimeMillis();
System.out.println("Time taken to create active user entries: " + ((en - st) / 1000) + " sec");
}

sanityCheckAPIs(process.getProcess());
allUserIds.clear();
allPrimaryUserIds.clear();
Expand All @@ -474,7 +509,7 @@ public void testCreatingOneMillionUsers() throws Exception {

FeatureFlagTestContent.getInstance(process.getProcess())
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{
EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY});
EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY, EE_FEATURES.MFA, EE_FEATURES.DASHBOARD_LOGIN});
process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

Expand Down Expand Up @@ -896,6 +931,35 @@ private void measureOperations(Main main) throws Exception {
System.out.println("Update user metadata " + time);
}

{ // measure user counting
long time = measureTime(() -> {
try {
AuthRecipe.getUsersCount(main, null);
AuthRecipe.getUsersCount(main, new RECIPE_ID[]{RECIPE_ID.EMAIL_PASSWORD});
AuthRecipe.getUsersCount(main, new RECIPE_ID[]{RECIPE_ID.EMAIL_PASSWORD, RECIPE_ID.THIRD_PARTY});
} catch (Exception e) {
errorCount.incrementAndGet();
throw new RuntimeException(e);
}
return null;
});
System.out.println("User counting: " + time);
assert time < 3000;
}
{ // measure telemetry
long time = measureTime(() -> {
try {
FeatureFlag.getInstance(main).getPaidFeatureStats();
} catch (Exception e) {
errorCount.incrementAndGet();
throw new RuntimeException(e);
}
return null;
});
System.out.println("Telemetry: " + time);
assert time < 3000;
}

assertEquals(0, errorCount.get());
}

Expand Down

0 comments on commit 70bc4b8

Please sign in to comment.