Skip to content

Commit

Permalink
fix(tests): no longer starting scheduler in webserver tests
Browse files Browse the repository at this point in the history
closes #2032
  • Loading branch information
brian-mulier-p committed Sep 5, 2023
1 parent 516d5fb commit e02a72b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.kestra.webserver.controllers;

import io.kestra.core.models.triggers.Trigger;
import io.kestra.core.utils.Await;
import io.kestra.core.utils.IdUtils;
import io.kestra.jdbc.repository.AbstractJdbcFlowRepository;
import io.kestra.jdbc.repository.AbstractJdbcTriggerRepository;
Expand All @@ -18,9 +17,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.concurrent.TimeoutException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -36,35 +32,40 @@ class TriggerControllerTest extends JdbcH2ControllerTest {
@Inject
AbstractJdbcTriggerRepository jdbcTriggerRepository;


@BeforeEach
protected void init() throws TimeoutException {
jdbcFlowRepository.findAll()
.forEach(jdbcFlowRepository::delete);

protected void init() {
super.setup();
Await.until(() -> jdbcTriggerRepository.findAll().size() > 0, null, Duration.ofSeconds(10));
}

@SuppressWarnings("unchecked")
@Test
void search() {
String triggerFlowId = "schedule-trigger";
String triggerNamespace = "io.kestra.tests.schedule";

Trigger trigger = Trigger.builder()
.flowId(triggerFlowId)
.namespace(triggerNamespace)
.triggerId("schedule-every-min")
.build();

jdbcTriggerRepository.save(trigger);
jdbcTriggerRepository.save(trigger.toBuilder().triggerId("schedule-5-min").build());

PagedResults<Trigger> triggers = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/triggers/search?q=schedule-trigger&namespace=io.kestra.tests&sort=triggerId:asc"), Argument.of(PagedResults.class, Trigger.class));
assertThat(triggers.getTotal(), is(2L));

String searchedTriggerFlowId = "schedule-trigger";
String searchedTriggerNamespace = "io.kestra.tests.schedule";

assertThat(triggers.getResults(), Matchers.hasItems(
allOf(
hasProperty("triggerId", is("schedule-every-min")),
hasProperty("namespace", is(searchedTriggerNamespace)),
hasProperty("flowId", is(searchedTriggerFlowId))
hasProperty("namespace", is(triggerNamespace)),
hasProperty("flowId", is(triggerFlowId))
),
allOf(
hasProperty("triggerId", is("schedule-5-min")),
hasProperty("namespace", is(searchedTriggerNamespace)),
hasProperty("flowId", is(searchedTriggerFlowId))
hasProperty("namespace", is(triggerNamespace)),
hasProperty("flowId", is(triggerFlowId))
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected void setup() {
TestsUtils.loads(repositoryLoader);

if (!runner.isRunning()) {
runner.setSchedulerEnabled(false);
runner.run();
}
}
Expand Down

0 comments on commit e02a72b

Please sign in to comment.