forked from premiere/premiere-libtorrent
attempt to make unit tests more deterministic
This commit is contained in:
parent
b2937712a2
commit
48bc00cbb7
|
@ -965,7 +965,7 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(p->address() == remote.address());
|
||||
p->port = remote.port();
|
||||
p->source |= src;
|
||||
|
||||
|
||||
// if this peer has failed before, decrease the
|
||||
// counter to allow it another try, since somebody
|
||||
// else is appearantly able to connect to it
|
||||
|
@ -1013,7 +1013,7 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
INVARIANT_CHECK;
|
||||
|
||||
|
||||
bool found = false;
|
||||
iterator iter = std::lower_bound(
|
||||
m_peers.begin(), m_peers.end()
|
||||
|
@ -1207,7 +1207,7 @@ namespace libtorrent
|
|||
, match_peer_connection(c))
|
||||
!= m_peers.end());
|
||||
#endif
|
||||
|
||||
|
||||
TORRENT_ASSERT(p->connection == &c);
|
||||
TORRENT_ASSERT(!is_connect_candidate(*p));
|
||||
|
||||
|
|
|
@ -77,9 +77,13 @@ namespace lt = libtorrent;
|
|||
#include <conio.h>
|
||||
#endif
|
||||
|
||||
boost::uint32_t g_addr = 0x92343023;
|
||||
address rand_v4()
|
||||
{
|
||||
return address_v4(((boost::uint32_t(rand()) << 16) | rand()) & 0xffffffff);
|
||||
do {
|
||||
g_addr += 0x3080ca;
|
||||
} while (g_addr == 0);
|
||||
return address_v4(g_addr);
|
||||
}
|
||||
|
||||
#if TORRENT_USE_IPV6
|
||||
|
@ -91,14 +95,19 @@ address rand_v6()
|
|||
}
|
||||
#endif
|
||||
|
||||
static boost::uint16_t g_port = 0;
|
||||
|
||||
tcp::endpoint rand_tcp_ep()
|
||||
{
|
||||
return tcp::endpoint(rand_v4(), rand() + 1024);
|
||||
// make sure we don't procude the same "random" port twice
|
||||
g_port = (g_port + 1) % 14038;
|
||||
return tcp::endpoint(rand_v4(), g_port + 1024);
|
||||
}
|
||||
|
||||
udp::endpoint rand_udp_ep()
|
||||
{
|
||||
return udp::endpoint(rand_v4(), rand() + 1024);
|
||||
g_port = (g_port + 1) % 14037;
|
||||
return udp::endpoint(rand_v4(), g_port + 1024);
|
||||
}
|
||||
|
||||
std::map<std::string, boost::int64_t> get_counters(libtorrent::session& s)
|
||||
|
|
|
@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/ip_filter.hpp"
|
||||
#include "libtorrent/peer_info.hpp"
|
||||
#include "libtorrent/random.hpp"
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
@ -75,7 +76,7 @@ struct mock_peer_connection : peer_connection_interface
|
|||
virtual void peer_log(peer_log_alert::direction_t dir, char const* event
|
||||
, char const* fmt, ...) const
|
||||
{
|
||||
va_list v;
|
||||
va_list v;
|
||||
va_start(v, fmt);
|
||||
vprintf(fmt, v);
|
||||
va_end(v);
|
||||
|
@ -513,13 +514,15 @@ TORRENT_TEST(erase_peers)
|
|||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
TEST_EQUAL(st.erased.size(), 0);
|
||||
torrent_peer* peer = add_peer(p, st, rand_tcp_ep());
|
||||
tcp::endpoint ep = rand_tcp_ep();
|
||||
torrent_peer* peer = add_peer(p, st, ep);
|
||||
TEST_CHECK(peer);
|
||||
if (peer == NULL || st.erased.size() > 0)
|
||||
{
|
||||
fprintf(stderr, "unexpected rejection of peer: %d in list. "
|
||||
fprintf(stderr, "unexpected rejection of peer: %s | %d in list. "
|
||||
"added peer %p, erased %d peers\n"
|
||||
, p.num_peers(), peer, int(st.erased.size()));
|
||||
, print_endpoint(ep).c_str(), p.num_peers(), peer
|
||||
, int(st.erased.size()));
|
||||
}
|
||||
}
|
||||
TEST_EQUAL(p.num_peers(), 100);
|
||||
|
@ -862,7 +865,7 @@ TORRENT_TEST(incoming_size_limit)
|
|||
st.allow_multiple_connections_per_ip = false;
|
||||
peer_list p;
|
||||
t.m_p = &p;
|
||||
|
||||
|
||||
torrent_peer* peer1 = add_peer(p, st, ep("10.0.0.1", 8080));
|
||||
TEST_CHECK(peer1);
|
||||
TEST_EQUAL(p.num_peers(), 1);
|
||||
|
@ -908,7 +911,7 @@ TORRENT_TEST(new_peer_size_limit)
|
|||
st.allow_multiple_connections_per_ip = false;
|
||||
peer_list p;
|
||||
t.m_p = &p;
|
||||
|
||||
|
||||
torrent_peer* peer1 = add_peer(p, st, ep("10.0.0.1", 8080));
|
||||
TEST_CHECK(peer1);
|
||||
TEST_EQUAL(p.num_peers(), 1);
|
||||
|
|
Loading…
Reference in New Issue