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: standalone workflows now fail on top-level cycles #1997

Merged
merged 5 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ private Map<String, DependentResourceNode> toMap(Set<DependentResourceNode> node
}
map.put(node.getName(), node);
}
if (topLevelResources.size() == 0) {
throw new IllegalStateException(
"No top-level dependent resources found. This might indicate a cyclic Set of DependentResourceNode has been provided.");
}
return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
Expand All @@ -24,6 +25,22 @@ class WorkflowTest {

ExecutorService executorService = Executors.newCachedThreadPool();

@Test
void zeroTopLevelDRShouldThrowException() {
var dr1 = mock(DependentResource.class);
var dr2 = mock(DependentResource.class);
var dr3 = mock(DependentResource.class);

var cyclicWorkflowBuilderSetup = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1).dependsOn()
.addDependentResource(dr2).dependsOn(dr1)
.addDependentResource(dr3).dependsOn(dr2)
.addDependentResource(dr1).dependsOn(dr2);

assertThrows(IllegalStateException.class,
cyclicWorkflowBuilderSetup::build);
}

@Test
void calculatesTopLevelResources() {
var dr1 = mock(DependentResource.class);
Expand Down