forked from premiere/premiere-libtorrent
use standard library for suspending threads (#855)
use standard library for suspending threads
This commit is contained in:
parent
be30bbd08b
commit
eda956f13a
|
@ -368,13 +368,7 @@ namespace libtorrent
|
|||
int counter = 0;
|
||||
while (log_async())
|
||||
{
|
||||
#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
|
||||
Sleep(1000);
|
||||
#elif defined TORRENT_BEOS
|
||||
snooze_until(system_time() + 1000000, B_SYSTEM_TIMEBASE);
|
||||
#else
|
||||
usleep(1000000);
|
||||
#endif
|
||||
std::this_thread::sleep_for(seconds(1));
|
||||
++counter;
|
||||
std::printf("\x1b[2J\x1b[0;0H\x1b[33m==== Waiting to shut down: %d ==== \x1b[0m\n\n"
|
||||
, counter);
|
||||
|
|
|
@ -424,17 +424,6 @@ void print_ses_rate(float time
|
|||
std::fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void test_sleep(int milliseconds)
|
||||
{
|
||||
#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
|
||||
Sleep(milliseconds);
|
||||
#elif defined TORRENT_BEOS
|
||||
snooze_until(system_time() + std::int64_t(milliseconds) * 1000, B_SYSTEM_TIMEBASE);
|
||||
#else
|
||||
usleep(milliseconds * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef DWORD pid_type;
|
||||
#else
|
||||
|
@ -600,7 +589,7 @@ int start_proxy(int proxy_type)
|
|||
proxy_t t = { r, proxy_type };
|
||||
running_proxies.insert(std::make_pair(port, t));
|
||||
std::fprintf(stderr, "%s launched\n", time_now_string());
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
return port;
|
||||
}
|
||||
|
||||
|
@ -852,7 +841,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
|
|||
TORRENT_ASSERT(ses1->get_torrents().size() == 1);
|
||||
TORRENT_ASSERT(ses2->get_torrents().size() == 1);
|
||||
|
||||
// test_sleep(100);
|
||||
// std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
|
||||
if (connect_peers)
|
||||
{
|
||||
|
@ -937,7 +926,7 @@ int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
|
|||
if (r == 0) abort();
|
||||
web_server_pid = r;
|
||||
std::fprintf(stderr, "%s launched\n", time_now_string());
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
return port;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ EXPORT bool print_alerts(libtorrent::session& ses, char const* name
|
|||
|
||||
EXPORT void wait_for_listen(libtorrent::session& ses, char const* name);
|
||||
EXPORT void wait_for_downloading(libtorrent::session& ses, char const* name);
|
||||
EXPORT void test_sleep(int millisec);
|
||||
|
||||
EXPORT void create_random_files(std::string const& path, const int file_sizes[], int num_files);
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ void test_swarm(int flags)
|
|||
print_ses_rate(float(i), &st1, &st2, &st3);
|
||||
|
||||
if (st2.is_seeding && st3.is_seeding) break;
|
||||
test_sleep(1000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(1000));
|
||||
}
|
||||
|
||||
TEST_CHECK(tor2.status().is_seeding);
|
||||
|
|
|
@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <thread>
|
||||
|
||||
namespace lt = libtorrent;
|
||||
using namespace libtorrent;
|
||||
|
||||
TORRENT_TEST(limit)
|
||||
|
@ -193,7 +194,7 @@ TORRENT_TEST(extensions)
|
|||
|
||||
void post_torrent_added(alert_manager* mgr)
|
||||
{
|
||||
test_sleep(10);
|
||||
std::this_thread::sleep_for(lt::milliseconds(10));
|
||||
mgr->emplace_alert<torrent_added_alert>(torrent_handle());
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ void test_swarm()
|
|||
|
||||
print_ses_rate(i / 10.f, &st1, &st2, &st3);
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
TEST_CHECK(cnt["ses.num_unchoke_slots"] >= 2);
|
||||
|
|
|
@ -215,13 +215,13 @@ void test_checking(int flags = read_only_files)
|
|||
break;
|
||||
|
||||
if (st.errc) break;
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
}
|
||||
if (flags & incomplete_files)
|
||||
{
|
||||
TEST_CHECK(!st.is_seeding);
|
||||
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
st = tor1.status();
|
||||
TEST_CHECK(!st.is_seeding);
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ void test_checking(int flags = read_only_files)
|
|||
std::fprintf(stderr, "error: %s\n", st.errc.message().c_str());
|
||||
|
||||
// wait a while to make sure libtorrent survived the error
|
||||
test_sleep(1000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(1000));
|
||||
|
||||
st = tor1.status();
|
||||
TEST_CHECK(!st.is_seeding);
|
||||
|
|
|
@ -534,7 +534,7 @@ TORRENT_TEST(reject_fast)
|
|||
}
|
||||
print_session_log(*ses);
|
||||
s.close();
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
print_session_log(*ses);
|
||||
}
|
||||
|
||||
|
@ -558,7 +558,7 @@ TORRENT_TEST(invalid_suggest)
|
|||
// request for that piece index.
|
||||
send_suggest_piece(s, -234);
|
||||
send_unchoke(s);
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
print_session_log(*ses);
|
||||
|
||||
int len = read_message(s, recv_buffer, sizeof(recv_buffer));
|
||||
|
@ -653,7 +653,7 @@ TORRENT_TEST(reject_suggest)
|
|||
TEST_CHECK(fail_counter > 0);
|
||||
|
||||
s.close();
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
print_session_log(*ses);
|
||||
}
|
||||
|
||||
|
@ -713,7 +713,7 @@ TORRENT_TEST(suggest_order)
|
|||
TEST_CHECK(fail_counter > 0);
|
||||
|
||||
s.close();
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
print_session_log(*ses);
|
||||
}
|
||||
|
||||
|
@ -747,7 +747,7 @@ TORRENT_TEST(multiple_bitfields)
|
|||
print_session_log(*ses);
|
||||
|
||||
s.close();
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
print_session_log(*ses);
|
||||
}
|
||||
|
||||
|
@ -777,7 +777,7 @@ TORRENT_TEST(multiple_have_all)
|
|||
|
||||
s.close();
|
||||
print_session_log(*ses);
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
print_session_log(*ses);
|
||||
}
|
||||
|
||||
|
@ -802,7 +802,7 @@ TORRENT_TEST(dont_have)
|
|||
send_have_all(s);
|
||||
print_session_log(*ses);
|
||||
|
||||
test_sleep(300);
|
||||
std::this_thread::sleep_for(lt::milliseconds(300));
|
||||
print_session_log(*ses);
|
||||
|
||||
std::vector<peer_info> pi;
|
||||
|
@ -863,7 +863,7 @@ TORRENT_TEST(dont_have)
|
|||
|
||||
print_session_log(*ses);
|
||||
|
||||
test_sleep(1000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(1000));
|
||||
|
||||
print_session_log(*ses);
|
||||
|
||||
|
|
|
@ -32,11 +32,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp" // for test_sleep
|
||||
#include <string.h> // for strcmp
|
||||
#include <cstring> // for std::strcmp
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
|
||||
namespace lt = libtorrent;
|
||||
using namespace libtorrent;
|
||||
|
||||
int touch_file(std::string const& filename, int size)
|
||||
|
@ -88,7 +89,7 @@ TORRENT_TEST(file_status)
|
|||
|
||||
// sleep for 3 seconds and then make sure the difference in timestamp is
|
||||
// between 2-4 seconds after touching it again
|
||||
test_sleep(3000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(3000));
|
||||
|
||||
touch_file("__test_timestamp__", 10);
|
||||
|
||||
|
@ -253,16 +254,16 @@ TORRENT_TEST(split_string)
|
|||
int ret = split_string(tags, 10, tags_str);
|
||||
|
||||
TEST_CHECK(ret == 10);
|
||||
TEST_CHECK(strcmp(tags[0], "this") == 0);
|
||||
TEST_CHECK(strcmp(tags[1], "is") == 0);
|
||||
TEST_CHECK(strcmp(tags[2], "a") == 0);
|
||||
TEST_CHECK(strcmp(tags[3], "test") == 0);
|
||||
TEST_CHECK(strcmp(tags[4], "string") == 0);
|
||||
TEST_CHECK(strcmp(tags[5], "to") == 0);
|
||||
TEST_CHECK(strcmp(tags[6], "be") == 0);
|
||||
TEST_CHECK(strcmp(tags[7], "split") == 0);
|
||||
TEST_CHECK(strcmp(tags[8], "and") == 0);
|
||||
TEST_CHECK(strcmp(tags[9], "it") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[0], "this") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[1], "is") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[2], "a") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[3], "test") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[4], "string") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[5], "to") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[6], "be") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[7], "split") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[8], "and") == 0);
|
||||
TEST_CHECK(std::strcmp(tags[9], "it") == 0);
|
||||
|
||||
// replace_extension
|
||||
std::string test = "foo.bar";
|
||||
|
@ -304,7 +305,7 @@ TORRENT_TEST(file)
|
|||
if (ec)
|
||||
std::fprintf(stderr, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
|
||||
TEST_EQUAL(ec, error_code());
|
||||
TEST_CHECK(strcmp(test_buf, "test") == 0);
|
||||
TEST_CHECK(std::strcmp(test_buf, "test") == 0);
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
@ -348,7 +349,7 @@ TORRENT_TEST(hard_link)
|
|||
if (ec)
|
||||
std::fprintf(stderr, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
|
||||
TEST_EQUAL(ec, error_code());
|
||||
TEST_CHECK(strcmp(test_buf, "abcdefghijklmnopqrstuvwxyz") == 0);
|
||||
TEST_CHECK(std::strcmp(test_buf, "abcdefghijklmnopqrstuvwxyz") == 0);
|
||||
f.close();
|
||||
|
||||
remove("original_file", ec);
|
||||
|
@ -387,8 +388,8 @@ TORRENT_TEST(coalesce_buffer)
|
|||
, ec.category().name(), ec.message().c_str());
|
||||
}
|
||||
TEST_EQUAL(ec, error_code());
|
||||
TEST_CHECK(strcmp(test_buf1, "test") == 0);
|
||||
TEST_CHECK(strcmp(test_buf2, "foobar") == 0);
|
||||
TEST_CHECK(std::strcmp(test_buf1, "test") == 0);
|
||||
TEST_CHECK(std::strcmp(test_buf2, "foobar") == 0);
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ void test_lsd()
|
|||
print_ses_rate(float(i), &st1, &st2);
|
||||
|
||||
if (st2.is_seeding /*&& st3.is_seeding*/) break;
|
||||
test_sleep(1000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(1000));
|
||||
}
|
||||
|
||||
TEST_CHECK(tor2.status().is_seeding);
|
||||
|
|
|
@ -101,7 +101,7 @@ void test_pex()
|
|||
|
||||
ses2.apply_settings(pack);
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
|
||||
// in this test, ses1 is a seed, ses2 is connected to ses1 and ses3.
|
||||
// the expected behavior is that ses2 will introduce ses1 and ses3 to each other
|
||||
|
@ -133,7 +133,7 @@ void test_pex()
|
|||
// through session 2
|
||||
if (st3.state == torrent_status::seeding) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
TEST_CHECK(st1.num_peers == 2 && st2.num_peers == 2 && st3.num_peers == 2)
|
||||
|
|
|
@ -178,7 +178,7 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false)
|
|||
// if nothing is being transferred after 2 seconds, we're failing the test
|
||||
if (st1.upload_payload_rate == 0 && i > 20) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
TEST_CHECK(!tor2.status().is_seeding);
|
||||
|
@ -218,7 +218,7 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false)
|
|||
std::cerr << int(st2.progress * 100) << "% " << std::endl;
|
||||
}
|
||||
if (st2.state == torrent_status::finished) break;
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
TEST_EQUAL(st2.state, torrent_status::finished);
|
||||
|
@ -281,7 +281,7 @@ done:
|
|||
|
||||
std::cerr << "removed" << std::endl;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
|
||||
std::cout << "re-adding" << std::endl;
|
||||
add_torrent_params p;
|
||||
|
@ -322,7 +322,7 @@ done:
|
|||
|
||||
if (st2.is_finished) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
// torrent 2 should not be seeding yet, it should
|
||||
|
@ -371,7 +371,7 @@ done:
|
|||
break;
|
||||
}
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
st2 = tor2.status();
|
||||
|
|
|
@ -173,7 +173,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
|||
for (int i = 0; i < timeout; ++i)
|
||||
{
|
||||
print_alerts(*s, "s", false, false, false, &alert_predicate);
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
|
||||
if (num_udp_announces() >= prev_udp_announces + 1
|
||||
&& num_peer_hits() > 0)
|
||||
|
|
|
@ -68,7 +68,7 @@ void wait_for_complete(lt::session& ses, torrent_handle h)
|
|||
last_change = clock_type::now();
|
||||
}
|
||||
if (clock_type::now() - last_change > seconds(10)) break;
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
}
|
||||
TEST_ERROR("torrent did not finish");
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ void test_remap_files_gather(storage_mode_t storage_mode = storage_mode_sparse)
|
|||
|
||||
if (peer_disconnects >= 2) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
torrent_status st2 = tor2.status();
|
||||
|
@ -215,7 +215,7 @@ void test_remap_files_gather(storage_mode_t storage_mode = storage_mode_sparse)
|
|||
|
||||
if (st2.progress == 1.0) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
st2 = tor2.status();
|
||||
|
@ -325,7 +325,7 @@ void test_remap_files_scatter(storage_mode_t storage_mode = storage_mode_sparse)
|
|||
|
||||
if (peer_disconnects >= 2) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
torrent_status st2 = tor2.status();
|
||||
|
@ -359,7 +359,7 @@ void test_remap_files_scatter(storage_mode_t storage_mode = storage_mode_sparse)
|
|||
|
||||
if (st2.progress == 1.0) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
st2 = tor2.status();
|
||||
|
@ -464,7 +464,7 @@ void test_remap_files_prio(storage_mode_t storage_mode = storage_mode_sparse)
|
|||
// torrent1 will attempt to connect to torrent2
|
||||
// make sure torrent2 is up and running by then
|
||||
tor2.resume();
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
tor1.resume();
|
||||
|
||||
std::fprintf(stderr, "\ntesting remap scatter prio\n\n");
|
||||
|
@ -508,7 +508,7 @@ void test_remap_files_prio(storage_mode_t storage_mode = storage_mode_sparse)
|
|||
|
||||
if (peer_disconnects >= 2) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
torrent_status st2 = tor2.status();
|
||||
|
|
|
@ -191,9 +191,9 @@ TORRENT_TEST(paused_session)
|
|||
|
||||
torrent_handle h = s.add_torrent(ps);
|
||||
|
||||
test_sleep(2000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(2000));
|
||||
h.resume();
|
||||
test_sleep(1000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(1000));
|
||||
|
||||
TEST_CHECK(!h.status().paused);
|
||||
}
|
||||
|
|
|
@ -280,7 +280,7 @@ void test_ssl(int test_idx, bool use_utp)
|
|||
TEST_CHECK(st2.state == torrent_status::downloading
|
||||
|| st2.state == torrent_status::checking_resume_data);
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
std::fprintf(stderr, "peer_errors: %d expected_errors: %d\n"
|
||||
|
|
|
@ -657,7 +657,7 @@ void test_fastresume(bool const test_deprecated)
|
|||
std::cout << "progress: 1.0f" << std::endl;
|
||||
break;
|
||||
}
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
// the whole point of the test is to have a resume
|
||||
|
@ -774,7 +774,7 @@ void test_rename_file_fastresume(bool test_deprecated)
|
|||
if (print_alerts(ses, "ses", true, true, true, &got_file_rename_alert)) renamed = true;
|
||||
torrent_status s = h.status();
|
||||
if (s.state == torrent_status::seeding && renamed) break;
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
std::cout << "stop loop" << std::endl;
|
||||
torrent_status s = h.status();
|
||||
|
@ -824,7 +824,7 @@ void test_rename_file_fastresume(bool test_deprecated)
|
|||
print_alerts(ses, "ses");
|
||||
if (stat.state == torrent_status::seeding)
|
||||
break;
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
TEST_CHECK(stat.state == torrent_status::seeding);
|
||||
|
||||
|
|
|
@ -30,17 +30,17 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp" // for test_sleep
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
namespace lt = libtorrent;
|
||||
using namespace libtorrent;
|
||||
|
||||
void fun(std::condition_variable* s, std::mutex* m, int* waiting, int i)
|
||||
|
@ -88,7 +88,7 @@ TORRENT_TEST(threads)
|
|||
while (waiting < 20)
|
||||
{
|
||||
l.unlock();
|
||||
test_sleep(10);
|
||||
std::this_thread::sleep_for(lt::milliseconds(10));
|
||||
l.lock();
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ TORRENT_TEST(threads)
|
|||
while (waiting < 6)
|
||||
{
|
||||
l.unlock();
|
||||
test_sleep(10);
|
||||
std::this_thread::sleep_for(lt::milliseconds(10));
|
||||
l.lock();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,13 +31,15 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
*/
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp" // for test_sleep
|
||||
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace lt = libtorrent;
|
||||
using namespace libtorrent;
|
||||
|
||||
void check_timer_loop(std::mutex& m, time_point& last, std::condition_variable& cv)
|
||||
|
@ -57,7 +59,6 @@ void check_timer_loop(std::mutex& m, time_point& last, std::condition_variable&
|
|||
|
||||
TORRENT_TEST(time)
|
||||
{
|
||||
|
||||
// make sure the time classes have correct semantics
|
||||
|
||||
TEST_EQUAL(total_milliseconds(milliseconds(100)), 100);
|
||||
|
@ -83,12 +84,12 @@ TORRENT_TEST(time)
|
|||
|
||||
std::mutex m;
|
||||
std::condition_variable cv;
|
||||
std::thread t1(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
std::thread t2(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
std::thread t3(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
std::thread t4(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
std::thread t1(&check_timer_loop, std::ref(m), std::ref(last), std::ref(cv));
|
||||
std::thread t2(&check_timer_loop, std::ref(m), std::ref(last), std::ref(cv));
|
||||
std::thread t3(&check_timer_loop, std::ref(m), std::ref(last), std::ref(cv));
|
||||
std::thread t4(&check_timer_loop, std::ref(m), std::ref(last), std::ref(cv));
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
|
||||
cv.notify_all();
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ void test_running_torrent(boost::shared_ptr<torrent_info> info, std::int64_t fil
|
|||
std::vector<int> ones(info->num_files(), 1);
|
||||
h.prioritize_files(ones);
|
||||
|
||||
// test_sleep(500);
|
||||
// std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
torrent_status st = h.status();
|
||||
|
||||
TEST_EQUAL(st.total_wanted, file_size); // we want the single file
|
||||
|
@ -336,7 +336,7 @@ TORRENT_TEST(duplicate_is_not_error)
|
|||
piece[i] = (i % 26) + 'A';
|
||||
|
||||
// calculate the hash for all pieces
|
||||
sha1_hash ph = hasher(&piece[0], piece.size()).final();
|
||||
sha1_hash ph = hasher(&piece[0], int(piece.size())).final();
|
||||
int num = t.num_pieces();
|
||||
TEST_CHECK(t.num_pieces() > 0);
|
||||
for (int i = 0; i < num; ++i)
|
||||
|
|
|
@ -355,7 +355,7 @@ TORRENT_TEST(udp_tracker)
|
|||
if (num_udp_announces() == prev_udp_announces + 1)
|
||||
break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
std::fprintf(stderr, "UDP: %d / %d\n", int(num_udp_announces())
|
||||
, int(prev_udp_announces) + 1);
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ TORRENT_TEST(udp_tracker)
|
|||
|
||||
// if we remove the torrent before it has received the response from the
|
||||
// tracker, it won't announce again to stop. So, wait a bit before removing.
|
||||
test_sleep(1000);
|
||||
std::this_thread::sleep_for(lt::milliseconds(1000));
|
||||
|
||||
s->remove_torrent(h);
|
||||
|
||||
|
@ -375,7 +375,7 @@ TORRENT_TEST(udp_tracker)
|
|||
if (num_udp_announces() == prev_udp_announces + 2)
|
||||
break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
std::fprintf(stderr, "UDP: %d / %d\n", int(num_udp_announces())
|
||||
, int(prev_udp_announces) + 1);
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
|
|||
// jobs failing right after, putting us back in upload mode. So,
|
||||
// give the disk some time to fail all disk jobs before resetting
|
||||
// upload mode to false
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
|
||||
// then we need to drain the alert queue, so the peer_disconnects
|
||||
// counter doesn't get incremented by old alerts
|
||||
|
@ -336,7 +336,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
|
|||
// if nothing is being transferred after 2 seconds, we're failing the test
|
||||
// if (!test_disk_full && st1.upload_payload_rate == 0 && i > 20) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
TEST_CHECK(tor2.status().is_seeding);
|
||||
|
|
|
@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/smart_ptr.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
namespace lt = libtorrent;
|
||||
using namespace libtorrent;
|
||||
|
||||
broadcast_socket* sock = 0;
|
||||
|
@ -176,7 +177,7 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con
|
|||
break;
|
||||
}
|
||||
if (upnp_handler->router_model() != "") break;
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
std::cerr << "router: " << upnp_handler->router_model() << std::endl;
|
||||
|
@ -196,7 +197,7 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con
|
|||
break;
|
||||
}
|
||||
if (callbacks.size() >= 2) break;
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
callback_info expected1 = {mapping1, 500, error_code()};
|
||||
|
@ -222,7 +223,7 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con
|
|||
break;
|
||||
}
|
||||
if (callbacks.size() >= 4) break;
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
// there should have been two DeleteMapping calls
|
||||
|
|
|
@ -112,7 +112,7 @@ void test_transfer()
|
|||
print_alerts(ses1, "ses1", true, true, true);
|
||||
print_alerts(ses2, "ses2", true, true, true);
|
||||
|
||||
test_sleep(500);
|
||||
std::this_thread::sleep_for(lt::milliseconds(500));
|
||||
|
||||
torrent_status st1 = tor1.status();
|
||||
torrent_status st2 = tor2.status();
|
||||
|
|
|
@ -191,7 +191,7 @@ void test_transfer(lt::session& ses, boost::shared_ptr<torrent_info> torrent_fil
|
|||
// the test. make sure to do so quickly
|
||||
if (!test_ban && keepalive && peer_disconnects >= 1) break;
|
||||
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
|
||||
cnt = get_counters(ses);
|
||||
|
@ -229,7 +229,7 @@ void test_transfer(lt::session& ses, boost::shared_ptr<torrent_info> torrent_fil
|
|||
break;
|
||||
std::fprintf(stderr, "cache_size: %d/%d\n", int(cnt["disk.read_cache_blocks"])
|
||||
, int(cnt["disk.disk_blocks_in_use"]));
|
||||
test_sleep(100);
|
||||
std::this_thread::sleep_for(lt::milliseconds(100));
|
||||
}
|
||||
TEST_CHECK(std::abs(int(cnt["disk.disk_blocks_in_use"]
|
||||
- (torrent_file->total_size() + 0x3fff) / 0x4000)) <= 2);
|
||||
|
|
Loading…
Reference in New Issue