From 3267abe4f28a887bc6b8e86e0f47caba171fff01 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Mon, 27 Oct 2014 09:11:45 +0100 Subject: [PATCH] Add tests forcing disconnection by reseting cynara Test 08 disconnects cynara during normal request-response scenario. Three subtestcases of 08 test differ only by resetting cynara daemon in different moments of sending request scenario. Test 09 disconnects cynara during request-cancel scenario Subtestcases differ by different moments of cynara reset. Change-Id: Ia3e9db87b7e3534c2e4b7e770b4d9a5739553ef4 --- tests/cynara-tests/test_cases_async.cpp | 141 ++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/tests/cynara-tests/test_cases_async.cpp b/tests/cynara-tests/test_cases_async.cpp index 0e04b33..ba8fb2d 100644 --- a/tests/cynara-tests/test_cases_async.cpp +++ b/tests/cynara-tests/test_cases_async.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -217,6 +218,141 @@ void tca07_request_with_data_insertion_func() client.checkCache(data[1], CYNARA_API_CACHE_MISS); } +void tca08_disconnect1_func() +{ + std::string testNo("08"); + int subtest = 1; + DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); + cynara_check_id id; + RequestEntity callbackData = {RequestFunction(), + CYNARA_API_ACCESS_DENIED, + CYNARA_CALL_CAUSE_ANSWER}; + Client client; + + client.createRequest({testNo, subtest}, id, callbackData); + client.assertStatus(READWRITE); + + dbusAccess.restartService(); + + client.process(); + client.assertStatus(READ); + client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT); +} + +void tca08_disconnect2_func() +{ + std::string testNo("08"); + int subtest = 2; + DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); + cynara_check_id id; + RequestEntity callbackData = {RequestFunction(), + CYNARA_API_ACCESS_DENIED, + CYNARA_CALL_CAUSE_ANSWER}; + Client client; + + client.createRequest({testNo, subtest}, id, callbackData); + client.assertStatus(READWRITE); + + dbusAccess.restartService(); + + client.process(); + client.assertStatus(READ); + + dbusAccess.restartService(); + + client.process(); + client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT); +} + +void tca08_disconnect3_func() +{ + std::string testNo("08"); + int subtest = 2; + cynara_check_id id; + RequestEntity callbackData = {[&](){ + DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); + dbusAccess.restartService(); + }, + CYNARA_API_ACCESS_DENIED, + CYNARA_CALL_CAUSE_ANSWER}; + Client client; + + client.createRequest({testNo, subtest}, id, callbackData); + client.assertStatus(READWRITE); + + client.process(); + client.assertStatus(READ); + + client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT); + client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT); +} + +void tca09_disconnect_and_cancel1_func() +{ + std::string testNo("09"); + int subtest = 1; + DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); + cynara_check_id id; + RequestEntity callbackData = {RequestFunction(), + CYNARA_API_ACCESS_DENIED, + CYNARA_CALL_CAUSE_CANCEL}; + + Client client; + + client.createRequest({testNo, subtest}, id, callbackData); + client.assertStatus(READWRITE); + + //send request + client.process(); + client.assertStatus(READ); + + dbusAccess.restartService(); + + client.cancel(id); + client.assertStatus(READWRITE); + + //send cancel + client.process(); + client.assertStatus(READ); + + //get answer + client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT); + client.assertStatus(READ); +} + +void tca09_disconnect_and_cancel2_func() +{ + std::string testNo("09"); + int subtest = 2; + DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); + cynara_check_id id; + RequestEntity callbackData = {RequestFunction(), + CYNARA_API_ACCESS_DENIED, + CYNARA_CALL_CAUSE_CANCEL}; + + Client client; + + client.createRequest({testNo, subtest}, id, callbackData); + client.assertStatus(READWRITE); + + //send request + client.process(); + client.assertStatus(READ); + + client.cancel(id); + client.assertStatus(READWRITE); + + dbusAccess.restartService(); + + //handle reconnect + client.process(); + client.assertStatus(READ); + + //get answer + client.process(CYNARA_API_SUCCESS, Client::EXPECT_TIMEOUT); + client.assertStatus(READ); +} + RUNNER_TEST_GROUP_INIT(cynara_async_tests) RUN_CYNARA_TEST(tca01_initialize) @@ -228,3 +364,8 @@ RUN_CYNARA_TEST(tca05_request_and_cancel2) RUN_CYNARA_TEST(tca05_request_and_cancel3) RUN_CYNARA_TEST(tca06_cancel_fail) RUN_CYNARA_TEST(tca07_request_with_data_insertion) +RUN_CYNARA_TEST(tca08_disconnect1) +RUN_CYNARA_TEST(tca08_disconnect2) +RUN_CYNARA_TEST(tca08_disconnect3) +RUN_CYNARA_TEST(tca09_disconnect_and_cancel1) +RUN_CYNARA_TEST(tca09_disconnect_and_cancel2) -- 2.7.4