Skip to content

Commit

Permalink
chore: only reset dialect result when it has changed (#1471)
Browse files Browse the repository at this point in the history
Only change the dialect result that is returned by the mock server
when the dialect has actually changed. This makes the test a bit
quicker, as we also don't have to close the SpannerPool after each
test.
  • Loading branch information
olavloite authored Feb 5, 2024
1 parent e3f58d1 commit aa4c0f5
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.sql.SQLException;
import java.sql.Savepoint;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Before;
Expand All @@ -54,6 +55,8 @@

@RunWith(Parameterized.class)
public class SavepointMockServerTest extends AbstractMockServerTest {
private static Dialect currentDialect;

@Parameter public Dialect dialect;

@Parameters(name = "dialect = {0}")
Expand All @@ -63,13 +66,18 @@ public static Object[] data() {

@Before
public void setupDialect() {
mockSpanner.putStatementResult(StatementResult.detectDialectResult(this.dialect));
// Only reset the dialect result when it has actually changed. This prevents the SpannerPool
// from being closed after each test, which again makes the test slower.
if (!Objects.equals(this.dialect, currentDialect)) {
currentDialect = this.dialect;
mockSpanner.putStatementResult(StatementResult.detectDialectResult(this.dialect));
SpannerPool.closeSpannerPool();
}
}

@After
public void clearRequests() {
mockSpanner.clearRequests();
SpannerPool.closeSpannerPool();
}

private String createUrl() {
Expand Down

0 comments on commit aa4c0f5

Please sign in to comment.