Compare commits

...

1 Commits

Author SHA1 Message Date
Roman Acevedo
55458a0428 test: add test on executor 2025-09-24 08:23:17 +02:00
4 changed files with 301 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
package io.kestra.core.runners;
import io.kestra.core.junit.annotations.KestraTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.TestInstance;
@KestraTest(startRunner = true)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class AbstractExecutorTest {
@Inject
protected TestRunnerUtils runnerUtils;
}

View File

@@ -0,0 +1,7 @@
package io.kestra.runner.mysql;
import io.kestra.jdbc.runner.JdbcExecutorTest;
public class MysqlExecutorTest extends JdbcExecutorTest {
}

View File

@@ -513,7 +513,7 @@ public class JdbcExecutor implements ExecutorInterface {
});
}
private void executionQueue(Either<Execution, DeserializationException> either) {
public void executionQueue(Either<Execution, DeserializationException> either) {
if (either.isRight()) {
log.error("Unable to deserialize an execution: {}", either.getRight().getMessage());
return;

View File

@@ -0,0 +1,278 @@
package io.kestra.jdbc.runner;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.kestra.core.junit.annotations.LoadFlows;
import io.kestra.core.models.executions.Execution;
import io.kestra.core.repositories.ExecutionRepositoryInterface;
import io.kestra.core.runners.AbstractExecutorTest;
import io.kestra.core.runners.AbstractRunnerTest;
import io.kestra.core.serializers.JacksonMapper;
import io.kestra.core.utils.Await;
import io.kestra.core.utils.Either;
import io.kestra.jdbc.JdbcTestUtils;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public abstract class JdbcExecutorTest extends AbstractExecutorTest {
public static final String NAMESPACE = "io.kestra.tests";
@Inject
private JdbcTestUtils jdbcTestUtils;
@BeforeAll
public void init() {
jdbcTestUtils.drop();
jdbcTestUtils.migrate();
}
@Inject
protected JdbcExecutor jdbcExecutor;
@Inject
private ExecutionRepositoryInterface executionRepository;
/**
* {@link AbstractRunnerTest#restartFailedWithFinally()} often fails on Mysql
* this tests tries to reproduce the bug in a simpler context
* this execution is one that was generated by this test when it failed
*/
@Test
@LoadFlows("flows/valids/restart-with-finally.yaml")
void debugRestartFailedWithFinally() throws JsonProcessingException {
var execution = JacksonMapper.ofJson().readValue("""
{
"tenantId": "main",
"id": "5gokrBx2Bgdwq428pp8FfO",
"namespace": "io.kestra.tests",
"flowId": "restart-with-finally",
"flowRevision": 1,
"taskRunList": [
{
"tenantId": "main",
"id": "6fDC4yvllUoL87vcU20gBW",
"executionId": "5gokrBx2Bgdwq428pp8FfO",
"namespace": "io.kestra.tests",
"flowId": "restart-with-finally",
"taskId": "hello",
"attempts": [
{
"state": {
"current": "SUCCESS",
"histories": [
{
"state": "CREATED",
"date": "2025-09-23T13:58:11.269109Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.269111Z"
},
{
"state": "SUCCESS",
"date": "2025-09-23T13:58:11.272912Z"
}
],
"duration": 0.003803000,
"endDate": "2025-09-23T13:58:11.272912Z",
"startDate": "2025-09-23T13:58:11.269109Z"
},
"workerId": "5695d2af-49be-43e7-b31c-64e190150e6b"
}
],
"outputs": {},
"state": {
"current": "SUCCESS",
"histories": [
{
"state": "CREATED",
"date": "2025-09-23T13:58:11.244352Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.267718Z"
},
{
"state": "SUCCESS",
"date": "2025-09-23T13:58:11.272936Z"
}
],
"duration": 0.028584000,
"endDate": "2025-09-23T13:58:11.272936Z",
"startDate": "2025-09-23T13:58:11.244352Z"
}
},
{
"tenantId": "main",
"id": "1pPRjIfVKXvOZoLOkABn87",
"executionId": "5gokrBx2Bgdwq428pp8FfO",
"namespace": "io.kestra.tests",
"flowId": "restart-with-finally",
"taskId": "fail_randomly",
"attempts": [
{
"state": {
"current": "FAILED",
"histories": [
{
"state": "CREATED",
"date": "2025-09-23T13:58:11.309287Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.309288Z"
},
{
"state": "FAILED",
"date": "2025-09-23T13:58:11.315404Z"
}
],
"duration": 0.006117000,
"endDate": "2025-09-23T13:58:11.315404Z",
"startDate": "2025-09-23T13:58:11.309287Z"
},
"workerId": "5695d2af-49be-43e7-b31c-64e190150e6b"
}
],
"outputs": {},
"state": {
"current": "SKIPPED",
"histories": [
{
"state": "CREATED",
"date": "2025-09-23T13:58:11.297189Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.309209Z"
},
{
"state": "FAILED",
"date": "2025-09-23T13:58:11.315426Z"
},
{
"state": "RESTARTED",
"date": "2025-09-23T13:58:11.487704Z"
},
{
"state": "SKIPPED",
"date": "2025-09-23T13:58:11.527186Z"
}
],
"duration": 0.229997000,
"endDate": "2025-09-23T13:58:11.527186Z",
"startDate": "2025-09-23T13:58:11.297189Z"
}
},
{
"tenantId": "main",
"id": "4oOj1UnTnWBOvBHznzBkpS",
"executionId": "5gokrBx2Bgdwq428pp8FfO",
"namespace": "io.kestra.tests",
"flowId": "restart-with-finally",
"taskId": "log",
"attempts": [
{
"state": {
"current": "SUCCESS",
"histories": [
{
"state": "CREATED",
"date": "2025-09-23T13:58:11.593248Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.593249Z"
},
{
"state": "SUCCESS",
"date": "2025-09-23T13:58:11.601594Z"
}
],
"duration": 0.008346000,
"endDate": "2025-09-23T13:58:11.601594Z",
"startDate": "2025-09-23T13:58:11.593248Z"
},
"workerId": "5695d2af-49be-43e7-b31c-64e190150e6b"
}
],
"outputs": {},
"state": {
"current": "SUCCESS",
"histories": [
{
"state": "CREATED",
"date": "2025-09-23T13:58:11.545959Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.593028Z"
},
{
"state": "SUCCESS",
"date": "2025-09-23T13:58:11.601619Z"
}
],
"duration": 0.055660000,
"endDate": "2025-09-23T13:58:11.601619Z",
"startDate": "2025-09-23T13:58:11.545959Z"
}
}
],
"labels": [
{
"key": "system.correlationId",
"value": "5gokrBx2Bgdwq428pp8FfO"
},
{
"key": "system.restarted",
"value": "true"
}
],
"state": {
"current": "RUNNING",
"histories": [
{
"state": "CREATED",
"date": "2025-09-23T13:58:11.229434Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.244594Z"
},
{
"state": "FAILED",
"date": "2025-09-23T13:58:11.458146Z"
},
{
"state": "RESTARTED",
"date": "2025-09-23T13:58:11.488893Z"
},
{
"state": "RUNNING",
"date": "2025-09-23T13:58:11.526898Z"
}
],
"duration": 0.297464000,
"startDate": "2025-09-23T13:58:11.229434Z"
},
"originalId": "5gokrBx2Bgdwq428pp8FfO",
"deleted": false,
"metadata": {
"attemptNumber": 2,
"originalCreatedDate": "2025-09-23T13:58:11.229439Z"
}
}
""", Execution.class);
executionRepository.save(execution);
jdbcExecutor.executionQueue(Either.left(execution));
Await.until(() -> {
var res = executionRepository.findById("main", "5gokrBx2Bgdwq428pp8FfO");
return res.isPresent() && res.get().getState().isSuccess();
});
}
}