aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRechi <Rechi@users.noreply.github.com>2017-12-31 22:57:28 +0100
committerGitHub <noreply@github.com>2017-12-31 22:57:28 +0100
commitdc587bd7ad07498a1668cfbc12eeaba80a309fa0 (patch)
tree550330c5868e86c25aa21936dc3f3c606ced6123
parentf3e4a62c7413c767f027fa8bed46b39ebe15ad0b (diff)
parent00e6955ab61e64fdfe86ee24a28375cbd2d09887 (diff)
Merge pull request #13280 from Rechi/webserverTest
[test] run WebServer on random port
-rw-r--r--xbmc/network/test/TestWebServer.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/xbmc/network/test/TestWebServer.cpp b/xbmc/network/test/TestWebServer.cpp
index 52718dcdbe..b43349a520 100644
--- a/xbmc/network/test/TestWebServer.cpp
+++ b/xbmc/network/test/TestWebServer.cpp
@@ -44,10 +44,11 @@
#include "utils/URIUtils.h"
#include "utils/Variant.h"
+#include <random>
+
using namespace XFILE;
#define WEBSERVER_HOST "localhost"
-#define WEBSERVER_PORT 23456
#define TEST_URL_JSONRPC "jsonrpc"
@@ -61,9 +62,19 @@ class TestWebServer : public testing::Test
protected:
TestWebServer()
: webserver(),
- baseUrl(StringUtils::Format("http://" WEBSERVER_HOST ":%d", WEBSERVER_PORT)),
sourcePath(XBMC_REF_FILE_PATH("xbmc/network/test/data/webserver/"))
- { }
+ {
+ static uint16_t port;
+ if (port == 0)
+ {
+ std::random_device rd;
+ std::mt19937 mt(rd());
+ std::uniform_int_distribution<uint16_t> dist(49152, 65535);
+ port = dist(mt);
+ }
+ webserverPort = port;
+ baseUrl = StringUtils::Format("http://" WEBSERVER_HOST ":%u", webserverPort);
+ }
~TestWebServer() override = default;
protected:
@@ -71,7 +82,7 @@ protected:
{
SetupMediaSources();
- webserver.Start(WEBSERVER_PORT, "", "");
+ webserver.Start(webserverPort, "", "");
webserver.RegisterRequestHandler(&m_jsonRpcHandler);
webserver.RegisterRequestHandler(&m_vfsHandler);
}
@@ -349,6 +360,7 @@ protected:
CHTTPVfsHandler m_vfsHandler;
std::string baseUrl;
std::string sourcePath;
+ uint16_t webserverPort;
};
TEST_F(TestWebServer, IsStarted)