Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ee featureflag cron job #778

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

## [6.0.11] - 2023-08-16

- Fixed feature flag cron job

## [6.0.10] - 2023-08-16

- Fixed an encoding/decoding issue for certain access token payloads
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
// }
//}

version = "6.0.10"
version = "6.0.11"


repositories {
Expand Down
4 changes: 2 additions & 2 deletions ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import java.util.List;

public class EEFeatureFlag implements io.supertokens.featureflag.EEFeatureFlagInterface {
public static final int INTERVAL_BETWEEN_SERVER_SYNC = 1000 * 3600 * 24; // 1 day.
private static final long INTERVAL_BETWEEN_DB_READS = (long) 1000 * 3600 * 4; // 4 hour.
public static final int INTERVAL_BETWEEN_SERVER_SYNC = 3600 * 24; // 1 day (in seconds).
private static final long INTERVAL_BETWEEN_DB_READS = (long) 1000 * 3600 * 4; // 4 hour (in millis).
public static final String REQUEST_ID = "licensecheck";

public static final String FEATURE_FLAG_KEY_IN_DB = "FEATURE_FLAG";
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/supertokens/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ private void init() throws IOException, StorageQueryException {
}
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
}
}
FeatureFlag.initForBaseTenant(this, CLIOptions.get(this).getInstallationPath() + "ee/");

MultitenancyHelper.init(this);
FeatureFlag.initForBaseTenant(this, CLIOptions.get(this).getInstallationPath() + "ee/");

try {
// load all configs for each of the tenants.
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/io/supertokens/test/FeatureFlagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import io.supertokens.ProcessState;
import io.supertokens.cronjobs.CronTask;
import io.supertokens.cronjobs.CronTaskTest;
import io.supertokens.cronjobs.Cronjobs;
import io.supertokens.cronjobs.syncCoreConfigWithDb.SyncCoreConfigWithDb;
import io.supertokens.emailpassword.EmailPassword;
import io.supertokens.featureflag.EE_FEATURES;
import io.supertokens.featureflag.FeatureFlag;
Expand All @@ -35,6 +39,7 @@
import io.supertokens.session.Session;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.test.httpRequest.HttpRequestForTesting;
import io.supertokens.test.multitenant.api.TestMultitenancyAPIHelper;
import io.supertokens.webserver.WebserverAPI;
import org.junit.*;
import org.junit.rules.TestRule;
Expand Down Expand Up @@ -702,4 +707,39 @@ public void testPaidFeaturesAreEnabledIfUsingInMemoryDatabase() throws Exception
process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

@Test
public void testNetworkCallIsMadeFromLicenseCheckCronJob() throws Exception {
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
String[] args = {"../"};

TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

// While adding license
TestMultitenancyAPIHelper.addLicense(OPAQUE_KEY_WITH_MULTITENANCY_FEATURE, process.getProcess());
ProcessState.getInstance(process.getProcess()).clear();

process.kill(false);


// Restart core and check if the call was made during init
process = TestingProcessManager.start(args);
process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.LICENSE_KEY_CHECK_NETWORK_CALL));

// ensure none of the tasks have an interval more than a day
for (CronTask task : Cronjobs.getInstance(process.getProcess()).getTasks()) {
assertTrue(task.getIntervalTimeSeconds() <= 3600 * 24);
assertTrue(task.getInitialWaitTimeSeconds() <= 3600 * 24);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change it only for the license key cronjob, or then move this to cronjob tests


process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}
}
Loading