more work on piece_picker unit test

This commit is contained in:
Arvid Norberg 2015-02-12 06:43:46 +00:00
parent 48b6eb1798
commit 01ee9cd9af
3 changed files with 49 additions and 2 deletions

View File

@ -1612,7 +1612,7 @@ namespace libtorrent
TORRENT_ASSERT(m_num_passed > 0); TORRENT_ASSERT(m_num_passed > 0);
--m_num_passed; --m_num_passed;
} }
m_downloads[download_state].erase(i); erase_download_piece(i);
p.download_state = piece_pos::piece_open; p.download_state = piece_pos::piece_open;
return; return;
} }

View File

@ -317,7 +317,6 @@ namespace libtorrent
boost::shared_ptr<request_callback> cb = requester(); boost::shared_ptr<request_callback> cb = requester();
if (cb) cb->debug_log("*** UDP_TRACKER [ timed out url: %s ]", tracker_req().url.c_str()); if (cb) cb->debug_log("*** UDP_TRACKER [ timed out url: %s ]", tracker_req().url.c_str());
#endif #endif
m_abort = true;
fail(error_code(errors::timed_out)); fail(error_code(errors::timed_out));
} }

View File

@ -1427,6 +1427,43 @@ int test_main()
TEST_EQUAL(p->num_have(), 3); TEST_EQUAL(p->num_have(), 3);
TEST_EQUAL(p->have_piece(2), true); TEST_EQUAL(p->have_piece(2), true);
// ========================================================
print_title("test piece passed (causing we_have)");
p = setup_picker("1111111", "* ", "", "0700000");
TEST_EQUAL(p->has_piece_passed(0), true);
TEST_EQUAL(p->has_piece_passed(1), false);
TEST_EQUAL(p->num_passed(), 1);
TEST_EQUAL(p->num_have(), 1);
p->mark_as_finished(piece_block(1,3), &tmp1);
TEST_EQUAL(p->num_passed(), 1);
TEST_EQUAL(p->num_have(), 1);
p->piece_passed(1);
TEST_EQUAL(p->num_passed(), 2);
TEST_EQUAL(p->num_have(), 2);
// ========================================================
print_title("test break_one_seed");
p = setup_picker("0000000", "* ", "", "0700000");
p->inc_refcount_all(&tmp1);
p->inc_refcount_all(&tmp2);
p->inc_refcount_all(&tmp3);
TEST_EQUAL(p->piece_stats(0).peer_count, 3);
p->dec_refcount(0, &tmp1);
TEST_EQUAL(p->piece_stats(0).peer_count, 2);
TEST_EQUAL(p->piece_stats(1).peer_count, 3);
TEST_EQUAL(p->piece_stats(2).peer_count, 3);
TEST_EQUAL(p->piece_stats(3).peer_count, 3);
// ======================================================== // ========================================================
print_title("test we dont have"); print_title("test we dont have");
@ -1515,6 +1552,17 @@ int test_main()
// ======================================================== // ========================================================
// make sure write_failed() and lock_piece() actually
// locks the piece, and that it won't be picked.
// also make sure restore_piece() unlocks it and makes
// it available for picking again.
// test mark_as_canceled()
// test get_download_queue()
// test get_requestors() (similar to get_downloaders())
/* /*
p.pick_pieces(peer1, picked, 1, false, 0, true); p.pick_pieces(peer1, picked, 1, false, 0, true);