improved tests to be able to run in parallel and added pex test

This commit is contained in:
Arvid Norberg 2007-12-30 09:36:01 +00:00
parent dfd563dfbb
commit ce506c63ca
10 changed files with 296 additions and 76 deletions

View File

@ -37,6 +37,7 @@ test-suite libtorrent :
[ run test_metadata_extension.cpp ]
[ run test_swarm.cpp ]
[ run test_lsd.cpp ]
[ run test_pex.cpp ]
[ run test_web_seed.cpp ]
[ run test_bandwidth_limiter.cpp ]
;

View File

@ -134,7 +134,8 @@ boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file)
boost::tuple<torrent_handle, torrent_handle, torrent_handle>
setup_transfer(session* ses1, session* ses2, session* ses3
, bool clear_files, bool use_metadata_transfer, bool connect_peers)
, bool clear_files, bool use_metadata_transfer, bool connect_peers
, std::string suffix)
{
using namespace boost::filesystem;
@ -146,11 +147,15 @@ setup_transfer(session* ses1, session* ses2, session* ses3
assert(ses3->id() != ses2->id());
create_directory("./tmp1");
std::ofstream file("./tmp1/temporary");
create_directory("./tmp1" + suffix);
std::ofstream file(("./tmp1" + suffix + "/temporary").c_str());
boost::intrusive_ptr<torrent_info> t = create_torrent(&file);
file.close();
if (clear_files) remove_all("./tmp2/temporary");
if (clear_files)
{
remove_all("./tmp2" + suffix + "/temporary");
remove_all("./tmp3" + suffix + "/temporary");
}
std::cerr << "generated torrent: " << t->info_hash() << std::endl;
@ -161,16 +166,16 @@ setup_transfer(session* ses1, session* ses2, session* ses3
// file pool will complain if two torrents are trying to
// use the same files
sha1_hash info_hash = t->info_hash();
torrent_handle tor1 = ses1->add_torrent(clone_ptr(t), "./tmp1");
torrent_handle tor1 = ses1->add_torrent(clone_ptr(t), "./tmp1" + suffix);
torrent_handle tor2;
torrent_handle tor3;
if (ses3) tor3 = ses3->add_torrent(clone_ptr(t), "./tmp3");
if (ses3) tor3 = ses3->add_torrent(clone_ptr(t), "./tmp3" + suffix);
if (use_metadata_transfer)
tor2 = ses2->add_torrent("http://non-existent-name.com/announce"
, t->info_hash(), 0, "./tmp2");
, t->info_hash(), 0, "./tmp2" + suffix);
else
tor2 = ses2->add_torrent(clone_ptr(t), "./tmp2");
tor2 = ses2->add_torrent(clone_ptr(t), "./tmp2" + suffix);
assert(ses1->get_torrents().size() == 1);
assert(ses2->get_torrents().size() == 1);

View File

@ -13,7 +13,7 @@ boost::tuple<libtorrent::torrent_handle, libtorrent::torrent_handle
, libtorrent::torrent_handle>
setup_transfer(libtorrent::session* ses1, libtorrent::session* ses2
, libtorrent::session* ses3, bool clear_files, bool use_metadata_transfer = true
, bool connect = true);
, bool connect = true, std::string suffix = "");
void start_web_server(int port);
void stop_web_server(int port);

View File

@ -12,11 +12,14 @@ using namespace libtorrent;
int read_message(stream_socket& s, char* buffer)
{
using namespace libtorrent::detail;
asio::read(s, asio::buffer(buffer, 4));
asio::error_code ec;
asio::read(s, asio::buffer(buffer, 4), asio::transfer_all(), ec);
TEST_CHECK(!ec);
char* ptr = buffer;
int length = read_int32(ptr);
asio::read(s, asio::buffer(buffer, length));
asio::read(s, asio::buffer(buffer, length), asio::transfer_all(), ec);
TEST_CHECK(!ec);
return length;
}
@ -30,7 +33,9 @@ void send_allow_fast(stream_socket& s, int piece)
char msg[] = "\0\0\0\x05\x11\0\0\0\0";
char* ptr = msg + 5;
write_int32(piece, ptr);
asio::write(s, asio::buffer(msg, 9));
asio::error_code ec;
asio::write(s, asio::buffer(msg, 9), asio::transfer_all(), ec);
TEST_CHECK(!ec);
}
void send_suggest_piece(stream_socket& s, int piece)
@ -39,13 +44,17 @@ void send_suggest_piece(stream_socket& s, int piece)
char msg[] = "\0\0\0\x05\x0d\0\0\0\0";
char* ptr = msg + 5;
write_int32(piece, ptr);
asio::write(s, asio::buffer(msg, 9));
asio::error_code ec;
asio::write(s, asio::buffer(msg, 9), asio::transfer_all(), ec);
TEST_CHECK(!ec);
}
void send_unchoke(stream_socket& s)
{
char msg[] = "\0\0\0\x01\x01";
asio::write(s, asio::buffer(msg, 5));
asio::error_code ec;
asio::write(s, asio::buffer(msg, 5), asio::transfer_all(), ec);
TEST_CHECK(!ec);
}
void do_handshake(stream_socket& s, sha1_hash const& ih, char* buffer)
@ -54,11 +63,14 @@ void do_handshake(stream_socket& s, sha1_hash const& ih, char* buffer)
" " // space for info-hash
"aaaaaaaaaaaaaaaaaaaa" // peer-id
"\0\0\0\x01\x0e"; // have_all
asio::error_code ec;
std::memcpy(handshake + 28, ih.begin(), 20);
asio::write(s, asio::buffer(handshake, sizeof(handshake) - 1));
asio::write(s, asio::buffer(handshake, sizeof(handshake) - 1), asio::transfer_all(), ec);
TEST_CHECK(!ec);
// read handshake
asio::read(s, asio::buffer(buffer, 68));
asio::read(s, asio::buffer(buffer, 68), asio::transfer_all(), ec);
TEST_CHECK(!ec);
TEST_CHECK(buffer[0] == 19);
TEST_CHECK(std::memcmp(buffer + 1, "BitTorrent protocol", 19) == 0);
@ -86,14 +98,14 @@ void test_reject_fast()
{
boost::intrusive_ptr<torrent_info> t = create_torrent();
sha1_hash ih = t->info_hash();
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48000, 49000));
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48900, 49000));
ses1.add_torrent(t, "./tmp1");
test_sleep(2000);
io_service ios;
stream_socket s(ios);
s.connect(tcp::endpoint(address::from_string("127.0.0.1"), 48000));
s.connect(tcp::endpoint(address::from_string("127.0.0.1"), ses1.listen_port()));
char recv_buffer[1000];
do_handshake(s, ih, recv_buffer);
@ -110,7 +122,11 @@ void test_reject_fast()
while (!allowed_fast.empty())
{
read_message(s, recv_buffer);
std::cerr << "msg: " << message_name[int(recv_buffer[0])] << std::endl;
int msg = recv_buffer[0];
if (msg >= 0 && msg < int(sizeof(message_name)/sizeof(message_name[0])))
std::cerr << message_name[msg] << std::endl;
else
std::cerr << msg << std::endl;
if (recv_buffer[0] != 0x6) continue;
using namespace libtorrent::detail;
@ -124,8 +140,11 @@ void test_reject_fast()
allowed_fast.erase(i);
// send reject request
recv_buffer[0] = 0x10;
asio::write(s, asio::buffer("\0\0\0\x0d", 4));
asio::write(s, asio::buffer(recv_buffer, 13));
asio::error_code ec;
asio::write(s, asio::buffer("\0\0\0\x0d", 4), asio::transfer_all(), ec);
TEST_CHECK(!ec);
asio::write(s, asio::buffer(recv_buffer, 13), asio::transfer_all(), ec);
TEST_CHECK(!ec);
}
}
@ -133,14 +152,14 @@ void test_respect_suggest()
{
boost::intrusive_ptr<torrent_info> t = create_torrent();
sha1_hash ih = t->info_hash();
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48000, 49000));
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48900, 49000));
ses1.add_torrent(t, "./tmp1");
test_sleep(2000);
io_service ios;
stream_socket s(ios);
s.connect(tcp::endpoint(address::from_string("127.0.0.1"), 48000));
s.connect(tcp::endpoint(address::from_string("127.0.0.1"), ses1.listen_port()));
char recv_buffer[1000];
do_handshake(s, ih, recv_buffer);
@ -160,7 +179,12 @@ void test_respect_suggest()
while (!suggested.empty() && fail_counter > 0)
{
read_message(s, recv_buffer);
std::cerr << "msg: " << message_name[int(recv_buffer[0])] << std::endl;
std::cerr << "msg: ";
int msg = recv_buffer[0];
if (msg >= 0 && msg < int(sizeof(message_name)/sizeof(message_name[0])))
std::cerr << message_name[msg] << std::endl;
else
std::cerr << msg << std::endl;
fail_counter--;
if (recv_buffer[0] != 0x6) continue;
@ -175,8 +199,11 @@ void test_respect_suggest()
suggested.erase(i);
// send reject request
recv_buffer[0] = 0x10;
asio::write(s, asio::buffer("\0\0\0\x0d", 4));
asio::write(s, asio::buffer(recv_buffer, 13));
asio::error_code ec;
asio::write(s, asio::buffer("\0\0\0\x0d", 4), asio::transfer_all(), ec);
TEST_CHECK(!ec);
asio::write(s, asio::buffer(recv_buffer, 13), asio::transfer_all(), ec);
TEST_CHECK(!ec);
}
TEST_CHECK(fail_counter > 0);
}

View File

@ -10,18 +10,18 @@
using boost::filesystem::remove_all;
void test_swarm()
void test_lsd()
{
using namespace libtorrent;
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48000, 49000));
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49000, 50000));
session ses3(fingerprint("LT", 0, 1, 0, 0), std::make_pair(50000, 51000));
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48100, 49000));
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49100, 50000));
session ses3(fingerprint("LT", 0, 1, 0, 0), std::make_pair(50100, 51000));
// this is to avoid everything finish from a single peer
// immediately. To make the swarm actually connect all
// three peers before finishing.
float rate_limit = 90000;
float rate_limit = 180000;
ses1.set_upload_rate_limit(int(rate_limit));
ses2.set_download_rate_limit(int(rate_limit));
ses3.set_download_rate_limit(int(rate_limit));
@ -30,6 +30,7 @@ void test_swarm()
session_settings settings;
settings.allow_multiple_connections_per_ip = true;
settings.ignore_limits_on_local_network = false;
ses1.set_settings(settings);
ses2.set_settings(settings);
ses3.set_settings(settings);
@ -40,8 +41,8 @@ void test_swarm()
#ifndef TORRENT_DISABLE_ENCRYPTION
pe_settings pes;
pes.out_enc_policy = pe_settings::disabled;
pes.in_enc_policy = pe_settings::disabled;
pes.out_enc_policy = pe_settings::forced;
pes.in_enc_policy = pe_settings::forced;
ses1.set_pe_settings(pes);
ses2.set_pe_settings(pes);
ses3.set_pe_settings(pes);
@ -51,22 +52,31 @@ void test_swarm()
torrent_handle tor2;
torrent_handle tor3;
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, false);
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, false, "_lsd");
for (int i = 0; i < 10; ++i)
for (int i = 0; i < 30; ++i)
{
std::auto_ptr<alert> a;
a = ses1.pop_alert();
if (a.get())
while(a.get())
{
std::cerr << "ses1: " << a->msg() << "\n";
a = ses1.pop_alert();
}
a = ses2.pop_alert();
if (a.get())
while (a.get())
{
std::cerr << "ses2: " << a->msg() << "\n";
a = ses2.pop_alert();
}
a = ses3.pop_alert();
if (a.get())
while (a.get())
{
std::cerr << "ses3: " << a->msg() << "\n";
a = ses3.pop_alert();
}
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
@ -101,15 +111,15 @@ int test_main()
using namespace boost::filesystem;
// in case the previous run was terminated
try { remove_all("./tmp1"); } catch (std::exception&) {}
try { remove_all("./tmp2"); } catch (std::exception&) {}
try { remove_all("./tmp3"); } catch (std::exception&) {}
try { remove_all("./tmp1_lsd"); } catch (std::exception&) {}
try { remove_all("./tmp2_lsd"); } catch (std::exception&) {}
try { remove_all("./tmp3_lsd"); } catch (std::exception&) {}
test_swarm();
test_lsd();
remove_all("./tmp1");
remove_all("./tmp2");
remove_all("./tmp3");
remove_all("./tmp1_lsd");
remove_all("./tmp2_lsd");
remove_all("./tmp3_lsd");
return 0;
}

View File

@ -3,6 +3,7 @@
#include <boost/thread.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include "test.hpp"
#include "setup_transfer.hpp"
@ -17,21 +18,21 @@ void test_transfer(bool clear_files, bool disconnect
{
using namespace libtorrent;
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48000, 49000));
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49000, 50000));
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48100, 49000));
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49100, 50000));
ses1.add_extension(constructor);
ses2.add_extension(constructor);
torrent_handle tor1;
torrent_handle tor2;
#ifndef TORRENT_DISABLE_ENCRYPTION
pe_settings pes;
pes.out_enc_policy = pe_settings::disabled;
pes.in_enc_policy = pe_settings::disabled;
pes.out_enc_policy = pe_settings::forced;
pes.in_enc_policy = pe_settings::forced;
ses1.set_pe_settings(pes);
ses2.set_pe_settings(pes);
#endif
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, clear_files);
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, clear_files, true, true, "_meta");
for (int i = 0; i < 50; ++i)
{
@ -40,12 +41,18 @@ void test_transfer(bool clear_files, bool disconnect
if (!disconnect) tor2.status();
std::auto_ptr<alert> a;
a = ses1.pop_alert();
if (a.get())
while(a.get())
{
std::cerr << "ses1: " << a->msg() << "\n";
a = ses1.pop_alert();
}
a = ses2.pop_alert();
if (a.get())
while (a.get())
{
std::cerr << "ses2: " << a->msg() << "\n";
a = ses2.pop_alert();
}
if (disconnect && tor2.is_valid()) ses2.remove_torrent(tor2);
if (!disconnect && tor2.has_metadata()) break;
@ -57,15 +64,30 @@ void test_transfer(bool clear_files, bool disconnect
TEST_CHECK(tor2.has_metadata());
std::cerr << "waiting for transfer to complete\n";
for (int i = 0; i < 50; ++i)
for (int i = 0; i < 30; ++i)
{
tor2.status();
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
std::cerr
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< st1.num_peers << ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers
<< std::endl;
if (tor2.is_seed()) break;
test_sleep(100);
test_sleep(1000);
}
TEST_CHECK(tor2.is_seed());
if (tor2.is_seed()) std::cerr << "done\n";
using boost::filesystem::remove_all;
remove_all("./tmp1_meta");
remove_all("./tmp2_meta");
remove_all("./tmp3_meta");
}
int test_main()

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/hasher.hpp"
#include "libtorrent/pe_crypto.hpp"
#include "libtorrent/session.hpp"
#include <boost/filesystem/convenience.hpp>
#include "setup_transfer.hpp"
#include "test.hpp"
@ -79,8 +80,8 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
using namespace libtorrent;
using std::cerr;
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48000, 49000));
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49000, 50000));
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48800, 49000));
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49800, 50000));
pe_settings s;
s.out_enc_policy = libtorrent::pe_settings::enabled;
@ -106,7 +107,7 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
torrent_handle tor2;
using boost::tuples::ignore;
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, true, false);
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, true, false, true, "_pe");
std::cerr << "waiting for transfer to complete\n";
@ -115,12 +116,18 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
tor2.status();
std::auto_ptr<alert> a;
a = ses1.pop_alert();
if (a.get())
while(a.get())
{
std::cerr << "ses1: " << a->msg() << "\n";
a = ses1.pop_alert();
}
a = ses2.pop_alert();
if (a.get())
while (a.get())
{
std::cerr << "ses2: " << a->msg() << "\n";
a = ses2.pop_alert();
}
if (tor2.is_seed()) break;
test_sleep(100);
@ -128,6 +135,11 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
TEST_CHECK(tor2.is_seed());
if (tor2.is_seed()) std::cerr << "done\n";
using boost::filesystem::remove_all;
remove_all("./tmp1_pe");
remove_all("./tmp2_pe");
remove_all("./tmp3_pe");
}

132
test/test_pex.cpp Normal file
View File

@ -0,0 +1,132 @@
#include "libtorrent/session.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/extensions/ut_pex.hpp"
#include <boost/thread.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/filesystem/operations.hpp>
#include "test.hpp"
#include "setup_transfer.hpp"
using boost::filesystem::remove_all;
void test_pex()
{
using namespace libtorrent;
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48200, 49000));
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49200, 50000));
session ses3(fingerprint("LT", 0, 1, 0, 0), std::make_pair(50200, 51000));
// this is to avoid everything finish from a single peer
// immediately. To make the swarm actually connect all
// three peers before finishing.
float rate_limit = 500000;
ses1.set_upload_rate_limit(int(rate_limit));
ses2.set_download_rate_limit(int(rate_limit));
ses3.set_download_rate_limit(int(rate_limit));
// make the peer connecting the two worthless to transfer
// data, to force peer 3 to connect directly to peer 1 through pex
ses2.set_upload_rate_limit(200);
ses3.set_upload_rate_limit(int(rate_limit / 2));
ses1.add_extension(&create_ut_pex_plugin);
ses2.add_extension(&create_ut_pex_plugin);
session_settings settings;
settings.allow_multiple_connections_per_ip = true;
settings.ignore_limits_on_local_network = false;
ses1.set_settings(settings);
ses2.set_settings(settings);
ses3.set_settings(settings);
#ifndef TORRENT_DISABLE_ENCRYPTION
pe_settings pes;
pes.out_enc_policy = pe_settings::forced;
pes.in_enc_policy = pe_settings::forced;
ses1.set_pe_settings(pes);
ses2.set_pe_settings(pes);
ses3.set_pe_settings(pes);
#endif
torrent_handle tor1;
torrent_handle tor2;
torrent_handle tor3;
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, false, "_pex");
test_sleep(1000);
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1"), ses1.listen_port()));
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1"), ses3.listen_port()));
for (int i = 0; i < 40; ++i)
{
std::auto_ptr<alert> a;
a = ses1.pop_alert();
while(a.get())
{
std::cerr << "ses1: " << a->msg() << "\n";
a = ses1.pop_alert();
}
a = ses2.pop_alert();
while (a.get())
{
std::cerr << "ses2: " << a->msg() << "\n";
a = ses2.pop_alert();
}
a = ses3.pop_alert();
while (a.get())
{
std::cerr << "ses3: " << a->msg() << "\n";
a = ses3.pop_alert();
}
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
torrent_status st3 = tor3.status();
std::cerr
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< st1.num_peers << ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers << " - "
<< "\033[32m" << int(st3.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st3.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st3.progress * 100) << "% "
<< st3.num_peers
<< std::endl;
test_sleep(1000);
}
TEST_CHECK(tor2.is_seed());
TEST_CHECK(tor3.is_seed());
if (!tor2.is_seed() && tor3.is_seed()) std::cerr << "done\n";
}
int test_main()
{
using namespace libtorrent;
using namespace boost::filesystem;
// in case the previous run was terminated
try { remove_all("./tmp1_pex"); } catch (std::exception&) {}
try { remove_all("./tmp2_pex"); } catch (std::exception&) {}
try { remove_all("./tmp3_pex"); } catch (std::exception&) {}
test_pex();
remove_all("./tmp1_pex");
remove_all("./tmp2_pex");
remove_all("./tmp3_pex");
return 0;
}

View File

@ -36,14 +36,15 @@ void test_swarm()
session_settings settings;
settings.allow_multiple_connections_per_ip = true;
settings.ignore_limits_on_local_network = false;
ses1.set_settings(settings);
ses2.set_settings(settings);
ses3.set_settings(settings);
#ifndef TORRENT_DISABLE_ENCRYPTION
pe_settings pes;
pes.out_enc_policy = pe_settings::disabled;
pes.in_enc_policy = pe_settings::disabled;
pes.out_enc_policy = pe_settings::forced;
pes.in_enc_policy = pe_settings::forced;
ses1.set_pe_settings(pes);
ses2.set_pe_settings(pes);
ses3.set_pe_settings(pes);
@ -53,7 +54,7 @@ void test_swarm()
torrent_handle tor2;
torrent_handle tor3;
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false);
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, true, "_swarm");
float sum_dl_rate2 = 0.f;
float sum_dl_rate3 = 0.f;
@ -64,16 +65,25 @@ void test_swarm()
{
std::auto_ptr<alert> a;
a = ses1.pop_alert();
if (a.get())
while(a.get())
{
std::cerr << "ses1: " << a->msg() << "\n";
a = ses1.pop_alert();
}
a = ses2.pop_alert();
if (a.get())
while (a.get())
{
std::cerr << "ses2: " << a->msg() << "\n";
a = ses2.pop_alert();
}
a = ses3.pop_alert();
if (a.get())
while (a.get())
{
std::cerr << "ses3: " << a->msg() << "\n";
a = ses3.pop_alert();
}
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
@ -113,6 +123,7 @@ void test_swarm()
float average2 = sum_dl_rate2 / float(count_dl_rates2);
float average3 = sum_dl_rate3 / float(count_dl_rates3);
std::cerr << average2 << std::endl;
std::cerr << "average rate: " << (average2 / 1000.f) << "kB/s - "
<< (average3 / 1000.f) << "kB/s" << std::endl;
@ -159,20 +170,20 @@ int test_main()
using namespace boost::filesystem;
// in case the previous run was terminated
try { remove_all("./tmp1"); } catch (std::exception&) {}
try { remove_all("./tmp2"); } catch (std::exception&) {}
try { remove_all("./tmp3"); } catch (std::exception&) {}
try { remove_all("./tmp1_swarm"); } catch (std::exception&) {}
try { remove_all("./tmp2_swarm"); } catch (std::exception&) {}
try { remove_all("./tmp3_swarm"); } catch (std::exception&) {}
test_swarm();
test_sleep(2000);
TEST_CHECK(!exists("./tmp1/temporary"));
TEST_CHECK(!exists("./tmp2/temporary"));
TEST_CHECK(!exists("./tmp3/temporary"));
TEST_CHECK(!exists("./tmp1_swarm/temporary"));
TEST_CHECK(!exists("./tmp2_swarm/temporary"));
TEST_CHECK(!exists("./tmp3_swarm/temporary"));
remove_all("./tmp1");
remove_all("./tmp2");
remove_all("./tmp3");
remove_all("./tmp1_swarm");
remove_all("./tmp2_swarm");
remove_all("./tmp3_swarm");
return 0;
}

View File

@ -40,7 +40,7 @@ void test_transfer(torrent_info torrent_file, int proxy)
session ses;
ses.set_severity_level(alert::debug);
ses.listen_on(std::make_pair(49000, 50000));
ses.listen_on(std::make_pair(51000, 52000));
remove_all("./tmp1");
char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};