From: Eduardo Ramos Testillano (eramedu) Date: Tue, 28 Apr 2020 22:36:41 +0000 (+0200) Subject: Add new operation 'run' to test a specific test case X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=1f560cfaaea555f037a99a6790eade56434eb119;p=anna.git Add new operation 'run' to test a specific test case Not only updates iterator but also executes the case to avoid that another operation changes the pointer. --- diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 0c4a5bd..bb28699 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -1487,6 +1487,21 @@ bool Launcher::eventOperation(const std::string &operation, std::string &respons opt_response_content += anna::functions::asString(id); opt_response_content += ")"; } + else if(param1 == "run") { + if (numParams > 2) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Check 'HELP.md' for more information.", ANNA_FILE_LOCATION); + + if(param2 == "") throw anna::RuntimeException("Missing id for test run operation", ANNA_FILE_LOCATION); + int id = atoi(param2.c_str()); + if (testManager.runTestCase(id)) { + opt_response_content = "test executed for id provided ("; + } + else { + opt_response_content = "cannot found test id ("; + } + opt_response_content += anna::functions::asString(id); + opt_response_content += ")"; + } else if(param1 == "look") { if (numParams > 2) throw anna::RuntimeException("Wrong body content format on HTTP Request. Check 'HELP.md' for more information.", ANNA_FILE_LOCATION); diff --git a/example/diameter/launcher/resources/HELP.md b/example/diameter/launcher/resources/HELP.md index 5dbf7b5..69f0615 100644 --- a/example/diameter/launcher/resources/HELP.md +++ b/example/diameter/launcher/resources/HELP.md @@ -431,7 +431,11 @@ Anyway, the meaning is the same in both contexts. But now, when the amount is mi **test|goto|** -Updates current test pointer position. +Updates current test pointer position. Take into account, that 'test|next' will execute the next test case, not the one pointed with *goto*. + +**test|run|** + +Run the test case selected. **test|look[|id]** @@ -462,7 +466,7 @@ Restarts the whole programmed test list when finished the amount number of times **test|auto-reset|** -When cycling, current test cases can be soft (default) or hard reset. If no timeout has been configured for the test case, hard reset could prevent stuck on the next cycle for those test cases still in progress. +When cycling, current test cases can be soft or hard reset. If no timeout has been configured for the test case, hard reset could prevent stuck on the next cycle for those test cases still in progress. **test|initialized** @@ -520,8 +524,25 @@ This operation requires advanced programming and knowlegde of ANNA Diameter stac # HTTP Interface All the operations described above can be used through the optional HTTP interface. You only have - to define the http server at the command line with something like: '--httpServer localhost:9000'. -To send the task, we shall build the http POST request json body with the operation string. + to define the http server at the command line with something like: '--httpServer localhost:8000'. +REST API specification: + +## GET + +> curl -v --request GET localhost:8000 + +HTTP2 is not served, so, you should use *nginx* reverse proxy or similar, to pass HTTP1 requests to the server, allowing the external use of HTTP2 clients like *nghttp*: + +> nghttp -v -H ":method: GET" "" + +### GET /xxxx + + + +## POST + +> curl -v --request POST -H "Content-Type: application/json" localhost:8000 -d@test.json - Json specification covers a subset for previous: +HTTP2 is not served, so, you should use *nginx* reverse proxy or similar, to pass HTTP1 requests to the server, allowing the external use of HTTP2 clients like *nghttp*: +> nghttp -v -H ":method: POST" -d test.json "" \ No newline at end of file diff --git a/include/anna/testing/TestManager.hpp b/include/anna/testing/TestManager.hpp index fec33e6..4f3bed2 100644 --- a/include/anna/testing/TestManager.hpp +++ b/include/anna/testing/TestManager.hpp @@ -175,6 +175,7 @@ class TestManager : public anna::timex::TimeEventObserver, public anna::Singleto void setInProgressLimit(unsigned int limit) throw() { a_inProgressLimit = limit; } // -1 = UINT_MAX (no limit) bool gotoTestCase(unsigned int id) throw(); + bool runTestCase(unsigned int id) throw(); TestCase *findTestCase(unsigned int id) const throw(); // id = -1 provides current test case triggered TestCase *getTestCase(unsigned int id, const std::string &description = "") throw(); // creates/reuses a test case diff --git a/source/testing/TestManager.cpp b/source/testing/TestManager.cpp index 20a29a2..a74ab6d 100644 --- a/source/testing/TestManager.cpp +++ b/source/testing/TestManager.cpp @@ -194,7 +194,7 @@ throw() { bool TestManager::configureTTPS(int testTicksPerSecond) throw() { - if (testTicksPerSecond == 0) { + if (testTicksPerSecond == 0) { if (a_clock) { a_timeController->cancel(a_clock); LOGDEBUG(anna::Logger::debug("Testing timer clock stopped !", ANNA_FILE_LOCATION)); @@ -260,6 +260,23 @@ bool TestManager::gotoTestCase(unsigned int id) throw() { return false; } +bool TestManager::runTestCase(unsigned int id) throw() { + test_pool_it it = a_testPool.find(id); + if (it != a_testPool.end()) { + a_currentTestIt = it; + + // execTestCases will get the next one, we must return 1 position: + if (a_currentTestIt == a_testPool.begin()) + a_currentTestIt = a_testPool.end(); + else + a_currentTestIt--; + + return execTestCases(1); + } + + return false; +} + TestCase *TestManager::findTestCase(unsigned int id) const throw() { // id = -1 provides current test case triggered if (!tests()) return NULL;