unit test cleanup (test_metadata_transfer)

This commit is contained in:
Arvid Norberg 2013-10-10 07:50:34 +00:00
parent 9395186a7d
commit 28041accc1
2 changed files with 4 additions and 13 deletions

View File

@ -215,7 +215,7 @@ bool print_alerts(libtorrent::session& ses, char const* name
if (predicate && predicate(*i)) ret = true; if (predicate && predicate(*i)) ret = true;
if (peer_disconnected_alert* p = alert_cast<peer_disconnected_alert>(*i)) if (peer_disconnected_alert* p = alert_cast<peer_disconnected_alert>(*i))
{ {
fprintf(stderr, "%s: %s [%s] (%s): %s\n", time_now_string(), name, (*i)->what(), print_endpoint(p->ip).c_str(), p->message().c_str()); fprintf(stderr, "%s: %s: [%s] (%s): %s\n", time_now_string(), name, (*i)->what(), print_endpoint(p->ip).c_str(), p->message().c_str());
} }
else if ((*i)->message() != "block downloading" else if ((*i)->message() != "block downloading"
&& (*i)->message() != "block finished" && (*i)->message() != "block finished"
@ -624,7 +624,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3
error_code ec; error_code ec;
create_directory("tmp1" + suffix, ec); create_directory("tmp1" + suffix, ec);
std::ofstream file(combine_path("tmp1" + suffix, "temporary").c_str()); std::ofstream file(combine_path("tmp1" + suffix, "temporary").c_str());
t = ::create_torrent(&file, piece_size, 9, true); t = ::create_torrent(&file, piece_size, 9, false);
file.close(); file.close();
if (clear_files) if (clear_files)
{ {

View File

@ -53,27 +53,22 @@ void test_transfer(bool clear_files, bool disconnect
// the sessions to destruct in parallel // the sessions to destruct in parallel
session_proxy p1; session_proxy p1;
session_proxy p2; session_proxy p2;
session_proxy p3;
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48100, 49000), "0.0.0.0", 0); session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48100, 49000), "0.0.0.0", 0);
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49100, 50000), "0.0.0.0", 0); session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49100, 50000), "0.0.0.0", 0);
session ses3(fingerprint("LT", 0, 1, 0, 0), std::make_pair(50100, 51000), "0.0.0.0", 0);
ses1.add_extension(constructor); ses1.add_extension(constructor);
ses2.add_extension(constructor); ses2.add_extension(constructor);
ses3.add_extension(constructor);
torrent_handle tor1; torrent_handle tor1;
torrent_handle tor2; torrent_handle tor2;
torrent_handle tor3;
#ifndef TORRENT_DISABLE_ENCRYPTION #ifndef TORRENT_DISABLE_ENCRYPTION
pe_settings pes; pe_settings pes;
pes.out_enc_policy = pe_settings::forced; pes.out_enc_policy = pe_settings::forced;
pes.in_enc_policy = pe_settings::forced; pes.in_enc_policy = pe_settings::forced;
ses1.set_pe_settings(pes); ses1.set_pe_settings(pes);
ses2.set_pe_settings(pes); ses2.set_pe_settings(pes);
ses3.set_pe_settings(pes);
#endif #endif
boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, clear_files, true, true, "_meta"); boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, NULL, clear_files, true, true, "_meta");
for (int i = 0; i < 80; ++i) for (int i = 0; i < 80; ++i)
{ {
@ -85,15 +80,13 @@ void test_transfer(bool clear_files, bool disconnect
if (disconnect && tor2.is_valid()) ses2.remove_torrent(tor2); if (disconnect && tor2.is_valid()) ses2.remove_torrent(tor2);
if (!disconnect if (!disconnect
&& tor2.status().has_metadata && tor2.status().has_metadata) break;
&& tor3.status().has_metadata) break;
test_sleep(100); test_sleep(100);
} }
if (disconnect) goto done; if (disconnect) goto done;
TEST_CHECK(tor2.status().has_metadata); TEST_CHECK(tor2.status().has_metadata);
TEST_CHECK(tor3.status().has_metadata);
std::cerr << "waiting for transfer to complete\n"; std::cerr << "waiting for transfer to complete\n";
for (int i = 0; i < 30; ++i) for (int i = 0; i < 30; ++i)
@ -114,12 +107,10 @@ done:
// this allows shutting down the sessions in parallel // this allows shutting down the sessions in parallel
p1 = ses1.abort(); p1 = ses1.abort();
p2 = ses2.abort(); p2 = ses2.abort();
p3 = ses3.abort();
error_code ec; error_code ec;
remove_all("tmp1_meta", ec); remove_all("tmp1_meta", ec);
remove_all("tmp2_meta", ec); remove_all("tmp2_meta", ec);
remove_all("tmp3_meta", ec);
} }
int test_main() int test_main()