improve waiting for mailserver in sendMessage tests
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 26 Aug 2016 13:59:05 +0000 (15:59 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 29 Aug 2016 08:48:01 +0000 (10:48 +0200)
Change-Id: I2b3691ef4829a395e8f676a4f18eab495a7b1f0d
Reviewed-on: http://gerrit.tine20.com/customers/3491
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Felamimail/Frontend/JsonTest.php

index d8a2ba7..190abac 100644 (file)
@@ -1556,15 +1556,21 @@ class Felamimail_Frontend_JsonTest extends TestCase
     {
         $messageToSend = $this->_getMessageData();
         $messageToSend['headers'] = array_merge($messageToSend['headers'], $addtionalHeaders);
-        $returned = $this->_json->saveMessage($messageToSend);
+        $this->_json->saveMessage($messageToSend);
         $this->_foldersToClear = array('INBOX', $this->_account->sent_folder);
 
-        // sleep for 2 secs because mailserver may be slower than expected
-        sleep(2);
-        
-        $result = $this->_getMessages($folderName);
-        $message = $this->_getMessageFromSearchResult($result, $messageToSend['subject']);
-        
+        $i = 0;
+        while ($i < 5) {
+            $result = $this->_getMessages($folderName);
+            $message = $this->_getMessageFromSearchResult($result, $messageToSend['subject']);
+            if (! empty($message)) {
+                break;
+            }
+            // sleep for 1 sec because mailserver may be slower than expected
+            sleep(1);
+            $i++;
+        }
+
         $this->assertTrue(! empty($message), 'Sent message not found.');
         
         return $message;