From b4f4fdbceeb860aba69f4f761f9934db2b8faf0f Mon Sep 17 00:00:00 2001 From: Charles Chan Date: Fri, 21 Dec 2018 13:55:29 -0800 Subject: [PATCH] Unit test fix - timeout is not correctly set in parallel execution environment Change-Id: Id3089c45ad217113f9c01c93e2047114b7fbccb4 --- .../impl/InOrderFlowObjectiveManager.java | 3 ++- .../impl/InOrderFlowObjectiveManagerTest.java | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/net/src/main/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManager.java b/core/net/src/main/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManager.java index 457c6e6e8b..f625e9ca53 100644 --- a/core/net/src/main/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManager.java +++ b/core/net/src/main/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManager.java @@ -63,7 +63,8 @@ public class InOrderFlowObjectiveManager extends FlowObjectiveManager { private final Logger log = LoggerFactory.getLogger(getClass()); // TODO Make queue timeout configurable - static int objTimeoutMs = 15000; + static final int DEFAULT_OBJ_TIMEOUT = 15000; + int objTimeoutMs = DEFAULT_OBJ_TIMEOUT; private Cache filtObjQueueHead; private Cache fwdObjQueueHead; diff --git a/core/net/src/test/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManagerTest.java b/core/net/src/test/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManagerTest.java index f7ba5bceff..459ea0831e 100644 --- a/core/net/src/test/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManagerTest.java +++ b/core/net/src/test/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManagerTest.java @@ -98,7 +98,7 @@ public class InOrderFlowObjectiveManagerTest { // Delay flow objectives OFFSET + rand(0, BOUND) millis private static final int DEFAULT_OFFSET = 10; // ms private static final int DEFAULT_BOUND = 40; // ms - private static final int TIMEOUT_THRESH = 100; // ms + private static final int TIMEOUT_THRESH = 500; // ms private static int offset = DEFAULT_OFFSET; private static int bound = DEFAULT_BOUND; @@ -186,7 +186,12 @@ public class InOrderFlowObjectiveManagerTest { @Before public void setUp() { + internalSetup(InOrderFlowObjectiveManager.DEFAULT_OBJ_TIMEOUT); + } + + private void internalSetup(int objTimeoutMs) { mgr = new InOrderFlowObjectiveManager(); + mgr.objTimeoutMs = objTimeoutMs; mgr.pipeliners.put(DEV1, pipeliner); mgr.executorService = newFixedThreadPool(4, groupedThreads("foo", "bar")); mgr.cfgService = createMock(ComponentConfigService.class); @@ -251,15 +256,14 @@ public class InOrderFlowObjectiveManagerTest { Lists.newArrayList(fwdTimeout, FWD1, FWD2)); // Reduce timeout so the unit test doesn't have to wait many seconds - InOrderFlowObjectiveManager.objTimeoutMs = TIMEOUT_THRESH; - setUp(); + internalSetup(TIMEOUT_THRESH); expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(2); expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(2); replay(mgr.flowObjectiveStore); // Force this objective to time out - offset = InOrderFlowObjectiveManager.objTimeoutMs * 2; + offset = mgr.objTimeoutMs * 2; expectFwdObjsTimeout.forEach(fwdObj -> mgr.forward(DEV1, fwdObj)); @@ -267,7 +271,7 @@ public class InOrderFlowObjectiveManagerTest { int expectedTime = (bound + offset) * 3; assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjsTimeout.size(), actualObjs.size())); - assertTrue(counter.get() != 0); + assertAfter(expectedTime, expectedTime * 5, () -> assertTrue(counter.get() != 0)); assertTrue(actualObjs.indexOf(fwdTimeout) < actualObjs.indexOf(FWD1)); verify(mgr.flowObjectiveStore);