IOT-2355: Change IPCA unit test agressive timeout.
authorSoemin Tjong <stjong@microsoft.com>
Wed, 24 May 2017 22:52:01 +0000 (15:52 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Wed, 7 Jun 2017 18:13:31 +0000 (18:13 +0000)
https://jira.iotivity.org/browse/IOT-2355

The IPCA unit test "IsIoTivityWorking" has failed sporadically.
This test directly uses IoTivity OC APIs to ensure that the underlying
IoTivity stack is working.
The 2 second timeout is incorrect, it should follow RFC 7252.

Change-Id: Iff640c2dbc2423e4865a4d2c8856a766d5345fa4
Signed-off-by: Soemin Tjong <stjong@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20375
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/IPCA/unittests/ipcaunittests.cpp
resource/IPCA/unittests/testelevatorclient.cpp

index 38bc538..cbca314 100644 (file)
@@ -109,11 +109,7 @@ TEST(IoTivityDirect, IsIoTivityWorking)
     // elevator server.
     loopCount = 0;
     const int TARGET_FLOOR = 3;
-    elevatorClient.SetTargetFloor(TARGET_FLOOR);
-    while ((loopCount++ < 20) && (g_testElevator1.GetCurrentFloor() != TARGET_FLOOR))
-    {
-        std::this_thread::sleep_for(std::chrono::milliseconds(100));
-    }
+    elevatorClient.SetTargetFloor(TARGET_FLOOR);    // SetTargetFloor() is synchronous.
     EXPECT_EQ(TARGET_FLOOR, g_testElevator1.GetCurrentFloor());
 
     // Confirm able to get current floor using IoTivity client API. The current floor should be
index 98ecbc7..08ef772 100644 (file)
@@ -83,12 +83,13 @@ bool ElevatorClient::StopObservation()
     return result == OC_STACK_OK ? true : false;\r
 }\r
 \r
-const int DEFAULT_WAITTIME = 2000;\r
-bool ElevatorClient::WaitForCallback(int waitingTime = DEFAULT_WAITTIME)\r
+// Outstanding requests should time out in 247 seconds (EXCHANGE_LIFETIME) per rfc 7252.\r
+const int DEFAULT_WAITTIME_MS = 247000;\r
+bool ElevatorClient::WaitForCallback(int waitTimeMs = DEFAULT_WAITTIME_MS)\r
 {\r
     std::unique_lock<std::mutex> lock { syncMutex };\r
 \r
-    if (syncCV.wait_for(lock, std::chrono::milliseconds{ waitingTime }) != std::cv_status::timeout)\r
+    if (syncCV.wait_for(lock, std::chrono::milliseconds{ waitTimeMs }) != std::cv_status::timeout)\r
     {\r
         return true;\r
     }\r