]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/testUtils/PingTest.java
upd: improve error message of ping tests
[gigi.git] / tests / org / cacert / gigi / testUtils / PingTest.java
index 20395878fb4411dc7251bd0166f8cfb2df0eef44..31f45c99b8143c3e0d40e66ffccc70568a186d0e 100644 (file)
@@ -12,7 +12,6 @@ import java.sql.SQLException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.pages.account.domain.DomainOverview;
@@ -34,15 +33,16 @@ public abstract class PingTest extends ClientTest {
     }
 
     protected void waitForPings(int count) throws SQLException, InterruptedException {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT COUNT(*) FROM domainPinglog");
-        long start = System.currentTimeMillis();
-        while (System.currentTimeMillis() - start < 10000) {
-            GigiResultSet rs = ps.executeQuery();
-            rs.next();
-            if (rs.getInt(1) >= count) {
-                break;
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT COUNT(*) FROM `domainPinglog`")) {
+            long start = System.currentTimeMillis();
+            while (System.currentTimeMillis() - start < 10000) {
+                GigiResultSet rs = ps.executeQuery();
+                rs.next();
+                if (rs.getInt(1) >= count) {
+                    break;
+                }
+                Thread.sleep(200);
             }
-            Thread.sleep(200);
         }
     }
 
@@ -52,6 +52,9 @@ public abstract class PingTest extends ClientTest {
         openConnection.setDoOutput(true);
         openConnection.getOutputStream().write(content.getBytes("UTF-8"));
         openConnection.getHeaderField("Location");
+        if (((HttpURLConnection) openConnection).getResponseCode() != 302) {
+            throw new Error(IOUtils.readURL(openConnection));
+        }
 
         String newcontent = IOUtils.readURL(cookie(u.openConnection(), cookie));
         Pattern dlink = Pattern.compile(DomainOverview.PATH + "([0-9]+)'>");