Skip to content

Commit

Permalink
HSEARCH-4783 Close the sessionFactory on failure to clear data in Reu…
Browse files Browse the repository at this point in the history
…sableOrmSetupHolder

In order to avoid cascading failures when one test fails to clear its
data.
  • Loading branch information
yrodiere committed Jan 27, 2023
1 parent 96d880f commit a2bc964
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.hibernate.search.mapper.orm.mapping.impl.HibernateOrmMapping;
import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.common.impl.Closer;
import org.hibernate.search.util.common.impl.SuppressingCloser;
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendConfiguration;
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock;
import org.hibernate.search.util.impl.test.function.ThrowingBiFunction;
Expand Down Expand Up @@ -328,6 +329,10 @@ private void setupSessionFactory(Object testInstance) {
clearAllData( sessionFactory );
}
catch (RuntimeException e) {
// Close the session factory (and consequently drop the schema) so that later tests
// are not affected by the failure.
new SuppressingCloser( e )
.push( this::tearDownSessionFactory );
throw new Error( "Failed to clear data before test execution: " + e.getMessage(), e );
}
return;
Expand Down Expand Up @@ -675,4 +680,5 @@ private enum IndexDataClearStrategy {
NONE,
DROP_AND_CREATE_SCHEMA
}

}

0 comments on commit a2bc964

Please sign in to comment.