Adjust restart of cynara in cynara-tests 15/37215/4
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 20 Mar 2015 18:27:07 +0000 (19:27 +0100)
committerZbigniew Jasinski <z.jasinski@samsung.com>
Fri, 27 Mar 2015 10:28:51 +0000 (03:28 -0700)
Use new enhanced mechanism, that restarts also socket units
in cynara-tests.

Change-Id: I2eba2709e86b27a1a693dcf9774e88b6abb6c69b

src/cynara-tests/test_cases_agent.cpp
src/cynara-tests/test_cases_async.cpp
src/cynara-tests/test_cases_db.cpp

index 51fab54..a8c74ae 100644 (file)
@@ -69,12 +69,6 @@ void setAgentPolicy(int expectedResult = CYNARA_API_SUCCESS)
     admin.setPolicies(cp, expectedResult);
 }
 
-void restartCynara()
-{
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
-    serviceManager.restartService();
-}
-
 void getAgentRequest(Agent &agent, AgentRequest &request, Client &client,
                      int expectedResult = CYNARA_API_SUCCESS,
                      Timeout::ExpectMode expectTimeoutMode = Timeout::ExpectMode::TIMEOUT)
@@ -140,7 +134,7 @@ void tcag05_agent_request_timeout_func()
     };
 
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::TIMEOUT,
-                         restartCynara, hangOnGetRequest);
+                         restartCynaraServiceAndSockets, hangOnGetRequest);
 }
 
 void tcag06_check_with_unregistered_agent_func()
@@ -185,8 +179,9 @@ void tcag07_get_request_func()
 
     auto testTimeLimit = std::chrono::seconds(5);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
 
     agentRequest.assertAction(data.m_client, data.m_user, data.m_privilege);
     agent.putResponse(AgentResponse::createAllow(agentRequest.id()));
@@ -213,8 +208,9 @@ void tcag08_get_request_and_respond_with_wrong_id_func()
 
     auto testTimeLimit = std::chrono::seconds(5);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     agentRequest.assertAction(data.m_client, data.m_user, data.m_privilege);
     agent.putResponse(AgentResponse::createAllow(agentRequest.id() + 1));
     client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_TIMEOUT, 2);
@@ -240,8 +236,9 @@ void tcag09_get_request_and_correct_responded_id_func()
 
     auto testTimeLimit = std::chrono::seconds(5);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     agentRequest.assertAction(data.m_client, data.m_user, data.m_privilege);
     agent.putResponse(AgentResponse::createAllow(agentRequest.id() + 1));
     client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_TIMEOUT, 2);
@@ -270,13 +267,15 @@ void tcag10_cancel_request_func()
 
     auto testTimeLimit = std::chrono::seconds(5);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     agentRequest.assertAction(data.m_client, data.m_user, data.m_privilege);
     client.cancel(id);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     agentRequest.assertCancel();
     agent.putResponse(AgentResponse::createCancel(id));
     client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_NO_TIMEOUT, 2);
@@ -303,15 +302,17 @@ void tcag11_cancel_processed_request_func()
 
     auto testTimeLimit = std::chrono::seconds(5);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     agentRequest.assertAction(data.m_client, data.m_user, data.m_privilege);
     agent.putResponse(AgentResponse::createCancel(id));
     client.cancel(id);
     // we do not expect getting the cancel request in the agent
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::TIMEOUT,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                         std::ref(client), CYNARA_API_SERVICE_NOT_AVAILABLE, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest), std::ref(client),
+                         CYNARA_API_SERVICE_NOT_AVAILABLE, Timeout::ExpectMode::TIMEOUT);
     client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_NO_TIMEOUT, 2);
 }
 
@@ -340,16 +341,19 @@ void tcag12_create_two_requests_func()
 
     auto testTimeLimit = std::chrono::seconds(5);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest1),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest1), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest2),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::IGNORE);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest2), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::IGNORE);
     client.cancel(id2);
     client.assertStatus(READWRITE);
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequest, std::ref(agent), std::ref(agentRequest3),
-                         std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+                         restartCynaraServiceAndSockets, getAgentRequest,
+                         std::ref(agent), std::ref(agentRequest3), std::ref(client),
+                         CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     agentRequest1.assertAction(data1.m_client, data1.m_user, data1.m_privilege);
     agentRequest2.assertAction(data2.m_client, data2.m_user, data2.m_privilege);
     agentRequest3.assertCancel();
@@ -380,9 +384,10 @@ void tcag13_create_many_requests_func()
         client.createRequest(data, ids[i], callbackData);
         client.assertStatus(READWRITE);
         auto testTimeLimit = std::chrono::seconds(5);
-        Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED, restartCynara,
-                             getAgentRequest, std::ref(agent), std::ref(agentRequests[i]),
-                             std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+        Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
+                             restartCynaraServiceAndSockets, getAgentRequest,
+                             std::ref(agent), std::ref(agentRequests[i]), std::ref(client),
+                             CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
         agentRequests[i].assertAction(data.m_client, data.m_user, data.m_privilege);
     };
     for (int i = numberOfRequests - 1; i >= 0; i--) {
@@ -410,15 +415,15 @@ void tcag14_client_disconnects_func()
         client.createRequest(data, id, callbackData);
         client.assertStatus(READWRITE);
         Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                             restartCynara, getAgentRequest, std::ref(agent),
-                             std::ref(agentRequest), std::ref(client),
+                             restartCynaraServiceAndSockets, getAgentRequest,
+                             std::ref(agent), std::ref(agentRequest), std::ref(client),
                              CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     };
     auto getAgentRequestWrap = [&agent, &agentRequest]() {
             agent.getRequest(agentRequest, CYNARA_API_SUCCESS);
         };
     Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
-                         restartCynara, getAgentRequestWrap);
+                         restartCynaraServiceAndSockets, getAgentRequestWrap);
     agentRequest.assertCancel();
 }
 
@@ -440,9 +445,10 @@ void tcag15_agent_disconnects_func()
     {
         Agent agent;
         auto testTimeLimit = std::chrono::seconds(5);
-        Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED, restartCynara,
-                             getAgentRequest, std::ref(agent), std::ref(agentRequest),
-                             std::ref(client), CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
+        Timeout::callAndWait(testTimeLimit, Timeout::ExpectMode::FINISHED,
+                             restartCynaraServiceAndSockets, getAgentRequest,
+                             std::ref(agent), std::ref(agentRequest), std::ref(client),
+                             CYNARA_API_SUCCESS, Timeout::ExpectMode::TIMEOUT);
     };
     client.process(CYNARA_API_SUCCESS, Client::TimeoutExpectation::EXPECT_NO_TIMEOUT, 2);
 }
index e866d53..1412fcd 100644 (file)
@@ -224,7 +224,6 @@ void tca08_disconnect1_func()
 {
     std::string testNo("08");
     int subtest = 1;
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
     cynara_check_id id;
     RequestEntity callbackData = {RequestFunction(),
                                   CYNARA_API_ACCESS_DENIED,
@@ -234,7 +233,7 @@ void tca08_disconnect1_func()
     client.createRequest({testNo, subtest}, id, callbackData);
     client.assertStatus(READWRITE);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
 
     client.process();
     client.assertStatus(READ);
@@ -245,7 +244,6 @@ void tca08_disconnect2_func()
 {
     std::string testNo("08");
     int subtest = 2;
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
     cynara_check_id id;
     RequestEntity callbackData = {RequestFunction(),
                                   CYNARA_API_ACCESS_DENIED,
@@ -255,12 +253,12 @@ void tca08_disconnect2_func()
     client.createRequest({testNo, subtest}, id, callbackData);
     client.assertStatus(READWRITE);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
 
     client.process();
     client.assertStatus(READ);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
 
     client.process();
     client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
@@ -271,10 +269,7 @@ void tca08_disconnect3_func()
     std::string testNo("08");
     int subtest = 2;
     cynara_check_id id;
-    RequestEntity callbackData = {[&](){
-                                           ServiceManager serviceManager(CynaraTestConsts::SERVICE);
-                                           serviceManager.restartService();
-                                       },
+    RequestEntity callbackData = {restartCynaraServiceAndSockets,
                                   CYNARA_API_ACCESS_DENIED,
                                   CYNARA_CALL_CAUSE_ANSWER};
     Client client;
@@ -293,7 +288,6 @@ void tca09_disconnect_and_cancel1_func()
 {
     std::string testNo("09");
     int subtest = 1;
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
     cynara_check_id id;
     RequestEntity callbackData = {RequestFunction(),
                                   CYNARA_API_ACCESS_DENIED,
@@ -308,7 +302,7 @@ void tca09_disconnect_and_cancel1_func()
     client.process();
     client.assertStatus(READ);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
 
     client.cancel(id);
     client.assertStatus(READWRITE);
@@ -326,7 +320,6 @@ void tca09_disconnect_and_cancel2_func()
 {
     std::string testNo("09");
     int subtest = 2;
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
     cynara_check_id id;
     RequestEntity callbackData = {RequestFunction(),
                                   CYNARA_API_ACCESS_DENIED,
@@ -344,7 +337,7 @@ void tca09_disconnect_and_cancel2_func()
     client.cancel(id);
     client.assertStatus(READWRITE);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
 
     //handle reconnect
     client.process();
@@ -390,8 +383,7 @@ void tca11_double_request_with_restart_func()
                                   CYNARA_CALL_CAUSE_ANSWER};
 
     RequestEntity callbackData = {[&](){
-                                      ServiceManager serviceManager(CynaraTestConsts::SERVICE);
-                                      serviceManager.restartService();
+                                      restartCynaraServiceAndSockets();
                                       client.createRequest({testNo}, id2, callbackData2);
                                   },
                                   CYNARA_API_ACCESS_DENIED,
index 16b3d91..a0f4d78 100644 (file)
@@ -200,7 +200,6 @@ void tcdb01_lockdown_init_failure_func()
 {
     Admin admin;
     Client cynara;
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
 
     const char *bucket = CYNARA_ADMIN_DEFAULT_BUCKET;
     const char *extra = nullptr;
@@ -213,7 +212,7 @@ void tcdb01_lockdown_init_failure_func()
     deleteDbFile(fakeBackupGuard);
     admin.setBucket(bucket, CYNARA_ADMIN_ALLOW, extra);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
     compareDbs(defDbAllow);
 }
 
@@ -230,7 +229,6 @@ void tcdb02_write_to_backup_failure_func()
 {
     Admin admin;
     Client cynara;
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
 
     const char *bucket = CYNARA_ADMIN_DEFAULT_BUCKET;
     const char *extra = nullptr;
@@ -243,7 +241,7 @@ void tcdb02_write_to_backup_failure_func()
     createDbFile(fakeBucketDumpFile);
     admin.setBucket(bucket, CYNARA_ADMIN_DENY, extra, CYNARA_API_OPERATION_FAILED);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
     compareDbs(defDbAllow);
 }
 
@@ -261,7 +259,6 @@ void tcdb03_invalid_and_valid_backup_removal_func()
 {
     Admin admin;
     Client cynara;
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
 
     const char *bucket = CYNARA_ADMIN_DEFAULT_BUCKET;
     const char *extra = nullptr;
@@ -271,12 +268,12 @@ void tcdb03_invalid_and_valid_backup_removal_func()
     createDbFile(defaultBucketDumpFile);
     admin.setBucket(bucket, CYNARA_ADMIN_ALLOW, extra, CYNARA_API_OPERATION_FAILED);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
     compareDbs(defDb);
 
     admin.setBucket(bucket, CYNARA_ADMIN_ALLOW, extra);
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
     compareDbs(defDbAllow);
 }
 
@@ -319,8 +316,6 @@ void tcdb04_dumped_file_binary_comparison_func()
  */
 void tcdb05_non_indexed_files_removal_func()
 {
-    ServiceManager serviceManager(CynaraTestConsts::SERVICE);
-
     std::vector<std::string> filenames = { "_broken-backup~", "_non-indexed-bucket",
                                            "some-file-that-doesnt-belong-here" };
 
@@ -329,7 +324,7 @@ void tcdb05_non_indexed_files_removal_func()
         createDbFile(garbageFilename);
     }
 
-    serviceManager.restartService();
+    restartCynaraServiceAndSockets();
     compareDbs(defDb);
 }