From 0af3dc144672dbaa7a60e50270a9744f6b68ee8d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 17 Jul 2018 20:58:14 +0100 Subject: Testability Silently pass siege tests if wrk isn't present. Add a test that uses curl such that functional testing remains. Change test port number to something less conflicty. --- icespider/unittests/testEmbedded.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/icespider/unittests/testEmbedded.cpp b/icespider/unittests/testEmbedded.cpp index d104977..e77b114 100644 --- a/icespider/unittests/testEmbedded.cpp +++ b/icespider/unittests/testEmbedded.cpp @@ -1,5 +1,6 @@ #define BOOST_TEST_MODULE TestEmbedded #include +#include #include #include @@ -7,7 +8,7 @@ class EmbeddedIceSpiderInstance : public IceSpider::Embedded::Listener { public: EmbeddedIceSpiderInstance() : - fd(listen(8080)) + fd(listen(18080)) { BOOST_REQUIRE_GE(fd, 0); } @@ -28,6 +29,11 @@ class EmbeddedIceSpiderRunner : public EmbeddedIceSpiderInstance { th.join(); } + static bool wrk_exists() + { + return boost::filesystem::exists("/usr/bin/wrk"); + } + std::thread th; }; @@ -44,11 +50,19 @@ BOOST_AUTO_TEST_CASE(startup_and_shutdown_cycle, * boost::unit_test::timeout(2)) BOOST_FIXTURE_TEST_SUITE(EmbeddedIceSpider, EmbeddedIceSpiderRunner); +BOOST_AUTO_TEST_CASE(simple_curl_test, + * boost::unit_test::timeout(5)) +{ + BOOST_REQUIRE_EQUAL(0, system("curl -s http://localhost:18080/")); +} + // Throw some requests at it, get a general performance overview BOOST_AUTO_TEST_CASE(quick_siege_test, * boost::unit_test::timeout(5)) { - BOOST_REQUIRE_EQUAL(0, system("wrk -t2 http://localhost:8080/ -c10 -T 15 -d 2")); + if (wrk_exists()) { + BOOST_REQUIRE_EQUAL(0, system("wrk -t2 http://localhost:18080/ -c10 -T 15 -d 2")); + } } // Throw lots of requests at it, get a good performance overview @@ -56,7 +70,9 @@ BOOST_AUTO_TEST_CASE(simple_performance_test, * boost::unit_test::disabled() // Not usually interested * boost::unit_test::timeout(15)) { - BOOST_REQUIRE_EQUAL(0, system("wrk -t20 http://localhost:8080/ -c100 -T 15")); + if (wrk_exists()) { + BOOST_REQUIRE_EQUAL(0, system("wrk -t20 http://localhost:18080/ -c100 -T 15")); + } } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3