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

Run tests through kafka #2005

Merged
merged 14 commits into from
Jan 30, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.akto.dao.testing.TestingRunResultDao;
import com.akto.dto.AccountSettings;
import com.akto.dto.ApiInfo;
import com.akto.dto.ApiInfo.ApiInfoKey;
import com.akto.dto.CustomAuthType;
import com.akto.dto.User;
import com.akto.dto.test_editor.Category;
Expand Down Expand Up @@ -45,6 +46,7 @@
import com.akto.store.TestingUtil;
import com.akto.test_editor.execution.VariableResolver;
import com.akto.testing.TestExecutor;
import com.akto.testing.Utils;
import com.akto.util.Constants;
import com.akto.util.enums.GlobalEnums;
import com.akto.util.enums.GlobalEnums.Severity;
Expand Down Expand Up @@ -334,7 +336,11 @@ public String runTestForGivenTemplate() {
int lastSampleIndex = sampleDataList.get(0).getSamples().size() - 1;

TestingRunConfig testingRunConfig = new TestingRunConfig();
testingRunResult = executor.runTestNew(infoKey, null, testingUtil, null, testConfig, testingRunConfig, true, testLogs);
List<String> samples = testingUtil.getSampleMessages().get(infoKey);
TestingRunResult testingRunResult = Utils.generateFailedRunResultForMessage(null, infoKey, testConfig.getInfo().getCategory().getName(), testConfig.getInfo().getSubCategory(), null,samples , null);
if(testingRunResult == null){
testingRunResult = executor.runTestNew(infoKey, null, testingUtil, null, testConfig, testingRunConfig, true, testLogs, samples.get(samples.size() - 1));
}
if (testingRunResult == null) {
testingRunResult = new TestingRunResult(
new ObjectId(), infoKey, testConfig.getInfo().getCategory().getName(), testConfig.getInfo().getSubCategory() ,Collections.singletonList(new TestResult(null, sampleDataList.get(0).getSamples().get(lastSampleIndex),
Expand Down
10 changes: 7 additions & 3 deletions apps/testing-cli/src/main/java/com/akto/testing_cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.LoggerFactory;

import com.akto.DaoInit;
import com.akto.dao.context.Context;
import com.akto.dao.test_editor.TestConfigYamlParser;
import com.akto.dao.test_editor.TestEditorEnums.ContextOperator;
import com.akto.dto.AccountSettings;
Expand All @@ -40,6 +41,7 @@
import com.akto.store.TestingUtil;
import com.akto.testing.ApiExecutor;
import com.akto.testing.TestExecutor;
import com.akto.testing.Utils;
import com.akto.util.ColorConstants;
import com.akto.util.VersionUtil;

Expand Down Expand Up @@ -317,11 +319,13 @@ public static void main(String[] args) {
for (String testSubCategory : testingRunConfig.getTestSubCategoryList()) {
TestConfig testConfig = testConfigMap.get(testSubCategory);
for (ApiInfo.ApiInfoKey it : apiInfoKeys) {

TestingRunResult testingRunResult = null;
try {
testingRunResult = testExecutor.runTestNew(it, null, testingUtil, null, testConfig,
testingRunConfig, false, new ArrayList<>());
List<String> samples = testingUtil.getSampleMessages().get(it);
testingRunResult = Utils.generateFailedRunResultForMessage(null, it, testConfig.getInfo().getCategory().getName(), testConfig.getInfo().getSubCategory(), null,samples , null);
if(testingRunResult == null){
testingRunResult = testExecutor.runTestNew(it, null, testingUtil, null, testConfig, null, false, new ArrayList<>(), samples.get(samples.size() - 1));
}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
15 changes: 12 additions & 3 deletions apps/testing/src/main/java/com/akto/testing/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.akto.rules.RequiredConfigs;
import com.akto.task.Cluster;
import com.akto.test_editor.execution.Executor;
import com.akto.testing.testing_with_kafka.TestingConsumer;
import com.akto.testing.testing_with_kafka.TestingProducer;
import com.akto.util.AccountTask;
import com.akto.util.Constants;
import com.akto.util.DashboardMode;
Expand Down Expand Up @@ -327,6 +329,10 @@ public void run() {
loggerMaker.infoAndAddToDb("os.arch: " + System.getProperty("os.arch"), LogDb.TESTING);
loggerMaker.infoAndAddToDb("os.version: " + System.getProperty("os.version"), LogDb.TESTING);

// create /testing-info folder in the memory from here
boolean val = Utils.createFolder(Constants.TESTING_STATE_FOLDER_PATH);
logger.info("Testing info folder status: " + val);

SingleTypeInfo.init();
while (true) {
AccountTask.instance.executeTaskForNonHybridAccounts(account -> {
Expand Down Expand Up @@ -536,7 +542,8 @@ public void run() {
summaryId = trrs.getId();
}

TestExecutor testExecutor = new TestExecutor();
TestingProducer testingProducer = new TestingProducer();
TestingConsumer testingConsumer = new TestingConsumer();
if (trrs.getState() == State.SCHEDULED) {
if (trrs.getMetadata()!= null && trrs.getMetadata().containsKey("pull_request_id") && trrs.getMetadata().containsKey("commit_sha_head") ) {
//case of github status push
Expand All @@ -546,8 +553,10 @@ public void run() {
}
RequiredConfigs.initiate();
if(!maxRetriesReached){
testExecutor.init(testingRun, summaryId, syncLimit);
raiseMixpanelEvent(summaryId, testingRun, accountId);
// init producer and the consumer here
// producer for testing is currently calls init functions from test-executor
testingProducer.initProducer(testingRun, summaryId, syncLimit);
testingConsumer.init();
}

} catch (Exception e) {
Expand Down
Loading
Loading