]> WPIA git - gigi.git/commitdiff
Stabelize Test email sender
authorFelix Dörre <felix@dogcraft.de>
Thu, 26 Jun 2014 13:36:43 +0000 (15:36 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 26 Jun 2014 13:36:43 +0000 (15:36 +0200)
src/org/cacert/gigi/email/TestEmailProvider.java
tests/org/cacert/gigi/testUtils/TestEmailReciever.java

index 009ecf930c134c508264dcd6ea8a503b6dfe7569..07343502303073313a9c7002d96c8bcac39f8b23 100644 (file)
@@ -26,8 +26,7 @@ class TestEmailProvider extends EmailProvider {
        public synchronized void sendmail(String to, String subject,
                        String message, String from, String replyto, String toname,
                        String fromname, String errorsto, boolean extra) throws IOException {
-               boolean sent = false;
-               while (!sent) {
+               while (true) {
                        assureLocalConnection();
                        try {
                                out.writeUTF("mail");
@@ -37,13 +36,20 @@ class TestEmailProvider extends EmailProvider {
                                write(from);
                                write(replyto);
                                out.flush();
-                               sent = true;
+                               return;
                        } catch (IOException e) {
                                client = null;
                        }
                }
        }
        private void assureLocalConnection() throws IOException {
+               if (out != null) {
+                       try {
+                               out.writeUTF("ping");
+                       } catch (IOException e) {
+                               client = null;
+                       }
+               }
                if (client == null || client.isClosed()) {
                        client = servs.accept();
                        out = new DataOutputStream(client.getOutputStream());
@@ -51,12 +57,18 @@ class TestEmailProvider extends EmailProvider {
                }
        }
        @Override
-       public String checkEmailServer(int forUid, String address)
+       public synchronized String checkEmailServer(int forUid, String address)
                        throws IOException {
-               assureLocalConnection();
-               out.writeUTF("challengeAddrBox");
-               out.writeUTF(address);
-               return in.readUTF();
+               while (true) {
+                       assureLocalConnection();
+                       try {
+                               out.writeUTF("challengeAddrBox");
+                               out.writeUTF(address);
+                               return in.readUTF();
+                       } catch (IOException e) {
+                               client = null;
+                       }
+               }
        }
 
        private void write(String to) throws IOException {
index 446d2aad769d59fe5efd55b71f3ebde148eaa23a..e0131a3b3265ad3adb1857448882d74759f9118d 100644 (file)
@@ -88,6 +88,7 @@ public class TestEmailReciever implements Runnable {
                                                dos.writeUTF("FAIL");
                                        }
                                        dos.flush();
+                               } else if (type.equals("ping")) {
                                } else {
                                        System.err.println("Unknown type: " + type);
                                }