From 0350e868674fb4bd6f81935a92af0d7f8a30f34a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 29 Dec 2009 17:49:24 +0000 Subject: [PATCH] fixed web seed unit test --- include/libtorrent/torrent.hpp | 2 +- src/torrent.cpp | 8 ++++++++ test/test_web_seed.cpp | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 1f1b84785..3a5baeb1c 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -219,7 +219,7 @@ namespace libtorrent std::string name() const; stat statistics() const { return m_stat; } - void add_stats(stat const& s) { m_stat += s; } + void add_stats(stat const& s); size_type bytes_left() const; int block_bytes_wanted(piece_block const& p) const; void bytes_done(torrent_status& st) const; diff --git a/src/torrent.cpp b/src/torrent.cpp index f5e952205..e533aad01 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5339,6 +5339,7 @@ namespace libtorrent if (is_paused()) { // let the stats fade out to 0 + accumulator += m_stat; m_stat.second_tick(tick_interval_ms); return; } @@ -5461,6 +5462,13 @@ namespace libtorrent m_stat.second_tick(tick_interval_ms); } + void torrent::add_stats(stat const& s) + { + // these stats are propagated to the session + // stats the next time second_tick is called + m_stat += s; + } + void torrent::request_time_critical_pieces() { // build a list of peers and sort it by download_queue_time diff --git a/test/test_web_seed.cpp b/test/test_web_seed.cpp index 06d0eeaf8..9ec54dee1 100644 --- a/test/test_web_seed.cpp +++ b/test/test_web_seed.cpp @@ -53,12 +53,10 @@ void test_transfer(boost::intrusive_ptr torrent_file, int proxy) session ses(fingerprint(" ", 0,0,0,0), 0); session_settings settings; - settings.ignore_limits_on_local_network = false; settings.max_queued_disk_bytes = 256 * 1024; ses.set_settings(settings); ses.set_alert_mask(~alert::progress_notification); ses.listen_on(std::make_pair(51000, 52000)); - ses.set_download_rate_limit(torrent_file->total_size() / 2); error_code ec; remove_all("./tmp2_web_seed", ec); @@ -94,7 +92,7 @@ void test_transfer(boost::intrusive_ptr torrent_file, int proxy) cache_status cs; - for (int i = 0; i < 15; ++i) + for (int i = 0; i < 10; ++i) { torrent_status s = th.status(); session_status ss = ses.status(); @@ -120,8 +118,10 @@ void test_transfer(boost::intrusive_ptr torrent_file, int proxy) if (th.is_seed()/* && ss.download_rate == 0.f*/) { - TEST_CHECK(ses.status().total_payload_download == total_size); TEST_CHECK(th.status().total_payload_download == total_size); + // we need to sleep here a bit to let the session sync with the torrent stats + test_sleep(1000); + TEST_CHECK(ses.status().total_payload_download == total_size); break; } test_sleep(500);