提交 11e20221 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use helper method for sleeping on port in use exception in TestPgServer

上级 ce5690e6
...@@ -22,6 +22,8 @@ import java.util.concurrent.ExecutionException; ...@@ -22,6 +22,8 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.h2.api.ErrorCode;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Server; import org.h2.tools.Server;
...@@ -45,19 +47,13 @@ public class TestPgServer extends TestBase { ...@@ -45,19 +47,13 @@ public class TestPgServer extends TestBase {
config.memory = true; config.memory = true;
config.mvStore = true; config.mvStore = true;
config.mvcc = true; config.mvcc = true;
// the sleeps are too mitigate "port in use" exceptions on Jenkins // testPgAdapter() starts server by itself without a wait so run it first
testLowerCaseIdentifiers();
Thread.sleep(100);
testPgAdapter(); testPgAdapter();
Thread.sleep(100); testLowerCaseIdentifiers();
testKeyAlias(); testKeyAlias();
Thread.sleep(100);
testKeyAlias(); testKeyAlias();
Thread.sleep(100);
testCancelQuery(); testCancelQuery();
Thread.sleep(100);
testBinaryTypes(); testBinaryTypes();
Thread.sleep(100);
testPrepareWithUnspecifiedType(); testPrepareWithUnspecifiedType();
} }
...@@ -70,10 +66,9 @@ public class TestPgServer extends TestBase { ...@@ -70,10 +66,9 @@ public class TestPgServer extends TestBase {
"mem:pgserver;DATABASE_TO_UPPER=false", "sa", "sa"); "mem:pgserver;DATABASE_TO_UPPER=false", "sa", "sa");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar(255))"); stat.execute("create table test(id int, name varchar(255))");
Server server = Server.createPgServer("-baseDir", getBaseDir(), Server server = createPgServer("-baseDir", getBaseDir(),
"-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "-pgPort", "5535", "-pgDaemon", "-key", "pgserver",
"mem:pgserver"); "mem:pgserver");
server.start();
try { try {
Connection conn2; Connection conn2;
conn2 = DriverManager.getConnection( conn2 = DriverManager.getConnection(
...@@ -98,6 +93,28 @@ public class TestPgServer extends TestBase { ...@@ -98,6 +93,28 @@ public class TestPgServer extends TestBase {
} }
} }
private Server createPgServer(String... args) throws SQLException {
Server server = Server.createPgServer(args);
int failures = 0;
for (;;) {
try {
server.start();
return server;
} catch (SQLException e) {
// the sleeps are too mitigate "port in use" exceptions on Jenkins
if (e.getErrorCode() != ErrorCode.EXCEPTION_OPENING_PORT_2 || ++failures > 10) {
throw e;
}
println("Sleeping");
try {
Thread.sleep(100);
} catch (InterruptedException e2) {
throw new RuntimeException(e2);
}
}
}
}
private void testPgAdapter() throws SQLException { private void testPgAdapter() throws SQLException {
deleteDb("pgserver"); deleteDb("pgserver");
Server server = Server.createPgServer( Server server = Server.createPgServer(
...@@ -120,9 +137,8 @@ public class TestPgServer extends TestBase { ...@@ -120,9 +137,8 @@ public class TestPgServer extends TestBase {
return; return;
} }
Server server = Server.createPgServer( Server server = createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver"); "-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver");
server.start();
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
try { try {
...@@ -347,9 +363,8 @@ public class TestPgServer extends TestBase { ...@@ -347,9 +363,8 @@ public class TestPgServer extends TestBase {
if (!getPgJdbcDriver()) { if (!getPgJdbcDriver()) {
return; return;
} }
Server server = Server.createPgServer( Server server = createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver"); "-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver");
server.start();
try { try {
Connection conn = DriverManager.getConnection( Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/pgserver", "sa", "sa"); "jdbc:postgresql://localhost:5535/pgserver", "sa", "sa");
...@@ -375,13 +390,8 @@ public class TestPgServer extends TestBase { ...@@ -375,13 +390,8 @@ public class TestPgServer extends TestBase {
return; return;
} }
// Sometimes the previous pg server has not finished shutting and we get Server server = createPgServer(
// "port in use", so sleep for a bit.
Thread.sleep(100);
Server server = Server.createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver"); "-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver");
server.start();
try { try {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty("user", "sa"); props.setProperty("user", "sa");
...@@ -437,9 +447,8 @@ public class TestPgServer extends TestBase { ...@@ -437,9 +447,8 @@ public class TestPgServer extends TestBase {
return; return;
} }
Server server = Server.createPgServer( Server server = createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver"); "-pgPort", "5535", "-pgDaemon", "-key", "pgserver", "mem:pgserver");
server.start();
try { try {
Properties props = new Properties(); Properties props = new Properties();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论