Fix unittest of things manager to wait a certain time to discover resources
authorJihun Ha <jihun.ha@samsung.com>
Mon, 22 Aug 2016 04:26:23 +0000 (13:26 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 22 Aug 2016 08:10:06 +0000 (08:10 +0000)
findCandidateResources can have the third parameter which is a waitTime
for discovering resources. If it is not specified, it acts like findResource.
It means, once any resource is discovered, it is immediately called, which
makes the test case failed if wrong resource is discovered.
To resolve this issue, we wait until a right resource id discovered.

Change-Id: Ib3d6f5595c955c8565d031d5fd2faf2ee904abe5
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10703
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/things-manager/unittests/ThingsManagerTest.cpp

index cdb3334..53812ff 100755 (executable)
@@ -944,10 +944,12 @@ void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResou
             lights.push_back((hostAddress + resourceURI));
 
             g_light = (*rsrc);
+            cv2.notify_all();
         }
         else
         {
             configurationResource = (*rsrc);
+            cv2.notify_all();
         }
     }
     cv2.notify_all();
@@ -1601,7 +1603,7 @@ TEST_F(ThingsManagerTest, testGetConfigurations)
     vector<string> types;
     types.push_back("oic.wk.con");
 
-    result = groupMgr->findCandidateResources(types, &foundResources);
+    result = groupMgr->findCandidateResources(types, &foundResources, 3);
 
     std::mutex blocker;
     std::unique_lock < std::mutex > lock(blocker);
@@ -1625,7 +1627,7 @@ TEST_F(ThingsManagerTest, testGetConfigurationsEmptyConfiguration)
     vector<string> types;
     types.push_back("oic.wk.con");
 
-    result = groupMgr->findCandidateResources(types, &foundResources);
+    result = groupMgr->findCandidateResources(types, &foundResources, 3);
 
     std::mutex blocker;
     std::unique_lock < std::mutex > lock(blocker);
@@ -1704,7 +1706,7 @@ TEST_F(ThingsManagerTest, testUpdateConfiguration)
 
     vector<string> types;
     types.push_back("oic.wk.con");
-    result = groupMgr->findCandidateResources(types, &foundResources);
+    result = groupMgr->findCandidateResources(types, &foundResources, 3);
 
     std::mutex blocker2;
     std::unique_lock < std::mutex > lock2(blocker2);
@@ -1728,7 +1730,7 @@ TEST_F(ThingsManagerTest, testUpdateConfigurationEmptyConfiguration)
 
     vector<string> types;
     types.push_back("oic.wk.con");
-    result = groupMgr->findCandidateResources(types, &foundResources);
+    result = groupMgr->findCandidateResources(types, &foundResources, 3);
 
     std::mutex blocker2;
     std::unique_lock < std::mutex > lock2(blocker2);
@@ -1772,7 +1774,7 @@ TEST_F(ThingsManagerTest, testReboot)
 
     vector<string> types;
     types.push_back("oic.wk.mnt");
-    result = groupMgr->findCandidateResources(types, &foundResources);
+    result = groupMgr->findCandidateResources(types, &foundResources, 3);
 
     std::mutex blocker;
     std::unique_lock < std::mutex > lock(blocker);
@@ -1809,7 +1811,7 @@ TEST_F(ThingsManagerTest, testFactoryReset)
 
     vector<string> types;
     types.push_back("oic.wk.mnt");
-    result = groupMgr->findCandidateResources(types, &foundResources);
+    result = groupMgr->findCandidateResources(types, &foundResources, 3);
 
     std::mutex blocker;
     std::unique_lock < std::mutex > lock(blocker);