hack to get test_stop_tracker_timeout working
This commit is contained in:
parent
540e1046e7
commit
a693565df0
|
@ -921,7 +921,7 @@ namespace {
|
|||
pid_type web_server_pid = 0;
|
||||
}
|
||||
|
||||
int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
|
||||
int start_web_server(bool ssl, bool chunked_encoding, bool keepalive, int min_interval)
|
||||
{
|
||||
int port = 2000 + static_cast<int>(lt::random(6000));
|
||||
error_code ec;
|
||||
|
@ -938,8 +938,8 @@ int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
|
|||
} while (ec);
|
||||
|
||||
char buf[200];
|
||||
std::snprintf(buf, sizeof(buf), "python ../web_server.py %d %d %d %d"
|
||||
, port, chunked_encoding , ssl, keepalive);
|
||||
std::snprintf(buf, sizeof(buf), "python ../web_server.py %d %d %d %d %d"
|
||||
, port, chunked_encoding, ssl, keepalive, min_interval);
|
||||
|
||||
std::printf("%s starting web_server on port %d...\n", time_now_string(), port);
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2
|
|||
, std::shared_ptr<lt::torrent_info>* torrent2 = 0);
|
||||
|
||||
EXPORT int start_web_server(bool ssl = false, bool chunked = false
|
||||
, bool keepalive = true);
|
||||
, bool keepalive = true, int min_interval = 30);
|
||||
|
||||
EXPORT void stop_web_server();
|
||||
EXPORT int start_proxy(int type);
|
||||
|
|
|
@ -620,7 +620,9 @@ TORRENT_TEST(tracker_proxy)
|
|||
|
||||
void test_stop_tracker_timeout(bool nostop)
|
||||
{
|
||||
int port = start_web_server();
|
||||
// trick the min interval so that the stopped anounce is permitted immediately
|
||||
// after the initial announce
|
||||
int port = start_web_server(false, false, true, -1);
|
||||
|
||||
auto count_stopped_events = [](session& ses)
|
||||
{
|
||||
|
@ -655,6 +657,7 @@ void test_stop_tracker_timeout(bool nostop)
|
|||
p.set_bool(settings_pack::announce_to_all_trackers, true);
|
||||
p.set_bool(settings_pack::announce_to_all_tiers, true);
|
||||
p.set_int(settings_pack::alert_mask, alert::all_categories);
|
||||
p.set_str(settings_pack::listen_interfaces, "0.0.0.0:6881");
|
||||
if (nostop)
|
||||
p.set_int(settings_pack::stop_tracker_timeout, 0);
|
||||
|
||||
|
@ -678,12 +681,17 @@ void test_stop_tracker_timeout(bool nostop)
|
|||
char tracker_url[200];
|
||||
std::snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce", port);
|
||||
announce_entry ae{tracker_url};
|
||||
// trick to avoid use of tracker immediately
|
||||
// FIXME
|
||||
//ae.next_announce = aux::time_now32() + seconds32(1);
|
||||
//ae.min_announce = aux::time_now32() + seconds32(1);
|
||||
h.add_tracker(ae);
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::vector<alert*> alerts;
|
||||
s.pop_alerts(&alerts);
|
||||
if (std::any_of(alerts.begin(), alerts.end()
|
||||
, [](alert* a) { return a->type() == tracker_reply_alert::alert_type; }))
|
||||
break;
|
||||
}
|
||||
|
||||
s.remove_torrent(h);
|
||||
|
||||
int const count = count_stopped_events(s);
|
||||
|
|
|
@ -79,6 +79,7 @@ class http_handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||
elif s.path.startswith('/announce'):
|
||||
s.send_response(200)
|
||||
response = 'd8:intervali1800e8:completei1e10:incompletei1e' + \
|
||||
'12:min intervali' + min_interval + 'e' + \
|
||||
'5:peers12:AAAABBCCCCDD' + \
|
||||
'6:peers618:EEEEEEEEEEEEEEEEFF' + \
|
||||
'e'
|
||||
|
@ -182,6 +183,7 @@ if __name__ == '__main__':
|
|||
chunked_encoding = sys.argv[2] != '0'
|
||||
use_ssl = sys.argv[3] != '0'
|
||||
keepalive = sys.argv[4] != '0'
|
||||
min_interval = sys.argv[5]
|
||||
|
||||
http_handler.protocol_version = 'HTTP/1.1'
|
||||
httpd = http_server_with_timeout(('127.0.0.1', port), http_handler)
|
||||
|
|
Loading…
Reference in New Issue