Skip to content

Commit d3eb91e

Browse files
committed
fix some synchronization issues in background bootstrapping mode
1 parent a9f3c11 commit d3eb91e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

embedded-database-spring-test-core/src/main/java/io/zonky/test/db/flyway/OptimizedFlywayTestExecutionListener.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,25 @@ public void beforeTestMethod(TestContext testContext) throws Exception {
112112
}
113113
}
114114

115-
protected void optimizedDbReset(TestContext testContext, FlywayTest annotation) throws Exception {
115+
protected synchronized void optimizedDbReset(TestContext testContext, FlywayTest annotation) throws Exception {
116116
if (annotation != null && annotation.invokeCleanDB() && annotation.invokeMigrateDB() && !annotation.invokeBaselineDB()) {
117117

118118
ApplicationContext applicationContext = testContext.getApplicationContext();
119-
120119
Flyway flywayBean = ReflectionTestUtils.invokeMethod(this, "getBean", applicationContext, Flyway.class, annotation.flywayName());
121-
FlywayDataSourceContext dataSourceContext = getDataSourceContext(applicationContext, flywayBean);
122120

123-
if (dataSourceContext != null && flywayBean != null) {
124-
prepareDataSourceContext(dataSourceContext, flywayBean, annotation);
121+
if (flywayBean != null) {
122+
FlywayDataSourceContext dataSourceContext = getDataSourceContext(applicationContext, flywayBean);
123+
124+
if (dataSourceContext != null) {
125125

126-
FlywayTest adjustedAnnotation = copyAnnotation(annotation, false, false, true);
127-
ReflectionTestUtils.invokeMethod(this, "dbResetWithAnnotation", testContext, adjustedAnnotation);
126+
dataSourceContext.getTarget(); // wait for completion of running flyway migration
127+
prepareDataSourceContext(dataSourceContext, flywayBean, annotation);
128128

129-
return;
129+
FlywayTest adjustedAnnotation = copyAnnotation(annotation, false, false, true);
130+
ReflectionTestUtils.invokeMethod(this, "dbResetWithAnnotation", testContext, adjustedAnnotation);
131+
132+
return;
133+
}
130134
}
131135
}
132136

0 commit comments

Comments
 (0)