From b28a1a903b6eb33effb75e43f1a9f77d08469010 Mon Sep 17 00:00:00 2001
From: felmer <franz-josef.elmer@id.ethz.ch>
Date: Wed, 30 May 2018 07:54:00 +0200
Subject: [PATCH] making all system tests which are subclasses of
 ObjectsImportTest more robust by waiting one second before finding the latest
 email (in case of async execution)

---
 .../dss/systemtest/api/v3/ObjectsImportTest.java | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/ObjectsImportTest.java b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/ObjectsImportTest.java
index 97808fd9202..e362ad88e49 100644
--- a/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/ObjectsImportTest.java
+++ b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/dss/systemtest/api/v3/ObjectsImportTest.java
@@ -233,18 +233,30 @@ public class ObjectsImportTest extends AbstractFileTest
 
     protected void assertNoEmails(long timestamp)
     {
-        Email latestEmail = EmailUtil.findLatestEmail();
+        Email latestEmail = waitAndFindLatestEmail();
         assertTrue("Timestamp: " + timestamp + ", Latest email: " + latestEmail, latestEmail == null || latestEmail.timestamp < timestamp);
     }
 
     protected void assertEmail(long timestamp, String expectedEmail, String expectedSubject)
     {
-        Email latestEmail = EmailUtil.findLatestEmail();
+        Email latestEmail = waitAndFindLatestEmail();
         assertTrue("Timestamp: " + timestamp + ", Latest email: " + latestEmail, latestEmail != null && latestEmail.timestamp >= timestamp);
         assertEquals(expectedEmail, latestEmail.to);
         assertTrue(latestEmail.subject, latestEmail.subject.contains(expectedSubject));
     }
 
+    private Email waitAndFindLatestEmail()
+    {
+        try
+        {
+            Thread.sleep(1000);
+        } catch (InterruptedException e)
+        {
+            // silently ignored
+        }
+        return EmailUtil.findLatestEmail();
+    }
+
     public static class ImportFile
     {
 
-- 
GitLab