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

stop database containers when spock execution ends #2843

Merged
merged 1 commit into from
May 12, 2022
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
@@ -0,0 +1,28 @@
package liquibase.extension.testing.testsystem.spock;

import liquibase.extension.testing.testsystem.TestSystem;
import org.spockframework.runtime.extension.IGlobalExtension;
import org.spockframework.runtime.model.SpecInfo;

public class LiquibaseGlobalExtension implements IGlobalExtension {
@Override
public void start() {

}

@Override
public void visitSpec(SpecInfo spec) {

}

@Override
public void stop() {
for (TestSystem startedTestSystem : LiquibaseIntegrationMethodInterceptor.startedTestSystems) {
try {
startedTestSystem.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
import org.spockframework.runtime.model.FieldInfo;
import org.spockframework.runtime.model.SpecInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.*;

public class LiquibaseIntegrationMethodInterceptor extends AbstractMethodInterceptor {

private static final SortedSet<TestSystem.Definition> testSystems = new TreeSet<>();
public static final Set<TestSystem> startedTestSystems = new HashSet<>();

private final SpecInfo spec;
private final LiquibaseIntegrationTestExtension.ErrorListener errorListener;
Expand Down Expand Up @@ -47,15 +45,6 @@ public void interceptSetupSpecMethod(IMethodInvocation invocation) throws Throwa
invocation.proceed();
}

@Override
public void interceptCleanupSpecMethod(IMethodInvocation invocation) throws Throwable {
final List<FieldInfo> containers = findAllContainers();
stopContainers(containers, invocation);

invocation.proceed();
}


private List<FieldInfo> findAllContainers() {
List<FieldInfo> returnList = new ArrayList<>();
for (FieldInfo fieldInfo : spec.getAllFields()) {
Expand All @@ -74,6 +63,7 @@ private static void startContainers(List<FieldInfo> containers, IMethodInvocatio
Assume.assumeTrue("Not running test against " + testSystem.getDefinition() + ": liquibase.sdk.testSystem.test is " + configuredTestSystems + " and liquibase.sdk.testSystem.skip is " + skippedTestSystems, testSystem.shouldTest());

testSystem.start();
startedTestSystems.add(testSystem);

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
liquibase.extension.testing.testsystem.spock.LiquibaseGlobalExtension