randomize proxy port to improve chances of unit tests passing

This commit is contained in:
Arvid Norberg 2012-06-09 16:58:16 +00:00
parent fa1c071c2f
commit f6450b91bb
5 changed files with 14 additions and 13 deletions

View File

@ -161,10 +161,12 @@ void stop_proxy(int port)
}
}
void start_proxy(int port, int proxy_type)
int start_proxy(int proxy_type)
{
using namespace libtorrent;
int port = 10000 + (rand() % 50000);
stop_proxy(port);
char const* type = "";
@ -203,6 +205,7 @@ void start_proxy(int port, int proxy_type)
fprintf(stderr, "launched\n");
// apparently delegate takes a while to open its listen port
test_sleep(500);
return port;
}
using namespace libtorrent;

View File

@ -69,7 +69,7 @@ setup_transfer(libtorrent::session* ses1, libtorrent::session* ses2
int start_web_server(bool ssl = false, bool chunked = false);
void stop_web_server();
void start_proxy(int port, int type);
int start_proxy(int type);
void stop_proxy(int port);
void stop_tracker();

View File

@ -134,16 +134,17 @@ void run_test(std::string const& url, int size, int status, int connected
TEST_CHECK(http_status == status || status == -1);
}
void run_suite(std::string const& protocol, proxy_settings const& ps, int port)
void run_suite(std::string const& protocol, proxy_settings ps, int port)
{
if (ps.type != proxy_settings::none)
{
start_proxy(ps.port, ps.type);
ps.port = start_proxy(ps.type);
}
char const* test_name[] = {"no", "SOCKS4", "SOCKS5"
, "SOCKS5 password protected", "HTTP", "HTTP password protected"};
std::cout << "\n\n********************** using " << test_name[ps.type]
<< " proxy **********************\n" << std::endl;
printf("\n\n********************** using %s proxy **********************\n"
, test_name[ps.type]);
typedef boost::optional<error_code> err;
// this requires the hosts file to be modified

View File

@ -247,13 +247,11 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48075, 49000), "0.0.0.0", 0, alert_mask);
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49075, 50000), "0.0.0.0", 0, alert_mask);
int proxy_port = (rand() % 30000) + 10000;
proxy_settings ps;
if (proxy_type)
{
start_proxy(proxy_port, proxy_type);
proxy_settings ps;
ps.port = start_proxy(proxy_type);
ps.hostname = "127.0.0.1";
ps.port = proxy_port;
ps.username = "testuser";
ps.password = "testpass";
ps.type = (proxy_settings::proxy_type)proxy_type;
@ -585,7 +583,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
stop_tracker();
stop_web_server();
}
if (proxy_type) stop_proxy(proxy_port);
if (proxy_type) stop_proxy(ps.port);
}
int test_main()

View File

@ -70,10 +70,9 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
if (proxy)
{
start_proxy(8002, proxy);
proxy_settings ps;
ps.port = start_proxy(proxy);
ps.hostname = "127.0.0.1";
ps.port = 8002;
ps.username = "testuser";
ps.password = "testpass";
ps.type = (proxy_settings::proxy_type)proxy;