From 9c411472a8aa8a218665d258f52c3d436ee9b58e Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 23 Mar 2020 07:24:50 +0200 Subject: Add some timed grace for assertion on log-lines It happens that logging is delayed, and rows are not available on disk right after an inspected event. Issue-ID: VID-647 Change-Id: Ic47cb2beff0be699f018ff6b5f264a57479bd7d0 Signed-off-by: Ittay Stern --- .../org/onap/vid/api/AsyncInstantiationBase.java | 18 +----------------- .../src/main/java/org/onap/vid/api/TestUtils.java | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'vid-automation/src/main/java/org/onap') diff --git a/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java b/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java index ee3982c19..f4dd6780a 100644 --- a/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java +++ b/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java @@ -17,13 +17,10 @@ import static vid.automation.test.utils.ExtendedHamcrestMatcher.hasItemsFromColl import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.Uninterruptibles; -import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -199,20 +196,7 @@ public class AsyncInstantiationBase extends BaseMsoApiTest { } protected void assertAndRetryIfNeeded(Runnable asserter, long timeoutInSeconds) { - final Instant expiry = Instant.now().plusSeconds(timeoutInSeconds); - while (true) { - try { - asserter.run(); - break; // we're cool, assertion passed - } catch (AssertionError fail) { - Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); - if (Instant.now().isAfter(expiry)) { - throw fail; - } else { - System.out.println("retrying after: " + fail); - } - } - } + TestUtils.assertAndRetryIfNeeded(timeoutInSeconds, asserter); } protected ImmutableList vidAuditStatusesCompletedWithErrors(String jobId) { diff --git a/vid-automation/src/main/java/org/onap/vid/api/TestUtils.java b/vid-automation/src/main/java/org/onap/vid/api/TestUtils.java index cc292caa7..af3cc57b9 100644 --- a/vid-automation/src/main/java/org/onap/vid/api/TestUtils.java +++ b/vid-automation/src/main/java/org/onap/vid/api/TestUtils.java @@ -11,10 +11,13 @@ import static vid.automation.test.utils.RegExMatcher.matchesRegEx; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.google.common.util.concurrent.Uninterruptibles; import java.io.IOException; import java.io.InputStream; +import java.time.Instant; import java.util.Map; import java.util.Scanner; +import java.util.concurrent.TimeUnit; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.apache.commons.text.RandomStringGenerator; @@ -99,6 +102,23 @@ public class TestUtils { return generator.generate(length); } + public static void assertAndRetryIfNeeded(long timeoutInSeconds, Runnable asserter) { + final Instant expiry = Instant.now().plusSeconds(timeoutInSeconds); + while (true) { + try { + asserter.run(); + break; // we're cool, assertion passed + } catch (AssertionError fail) { + Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); + if (Instant.now().isAfter(expiry)) { + throw fail; + } else { + System.out.println("retrying after: " + fail); + } + } + } + } + @DataProvider public static Object[][] trueAndFalse() { return new Object[][]{{true}, {false}}; -- cgit 1.2.3-korg