From 526012893379a88602d460ae861499a31a0e926e Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 26 Mar 2019 12:41:52 +0100 Subject: [PATCH] minor improvement to test_tracker. fix test output redirection on windows. tweak starting of web server in tests --- test/main.cpp | 18 ++++++++++++++++++ test/setup_transfer.cpp | 4 ++-- test/test_tracker.cpp | 5 ++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 5209c84c0..288f0d1cb 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -439,7 +439,25 @@ int EXPORT main(int argc, char const* argv[]) fflush(stdout); fflush(stderr); +#ifdef TORRENT_MINGW + // mingw has a buggy tmpfile() and tmpname() that needs a . prepended + // to it (or some other directory) + char temp_name[512]; + FILE* f = nullptr; + if (tmpnam_s(temp_name + 1, sizeof(temp_name) - 1) == 0) + { + temp_name[0] = '.'; + std::printf("using temporary filename %s\n", temp_name); + f = fopen(temp_name, "wb+"); + } + else + { + std::printf("failed to generate filename for redirecting " + "output: (%d) %s\n", errno, strerror(errno)); + } +#else FILE* f = tmpfile(); +#endif if (f != nullptr) { int ret1 = 0; diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index c892083b0..bbdeb44b4 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -542,7 +542,7 @@ int start_proxy(int proxy_type) if (i->second.type == proxy_type) { return i->first; } } - int port = 2000 + static_cast(lt::random(6000)); + int port = 10000 + static_cast(lt::random(50000)); error_code ec; io_service ios; @@ -976,7 +976,7 @@ int start_web_server(bool ssl, bool chunked_encoding, bool keepalive, int min_in if (r == 0) abort(); web_server_pid = r; std::printf("%s launched\n", time_now_string()); - std::this_thread::sleep_for(lt::milliseconds(500)); + std::this_thread::sleep_for(lt::milliseconds(1000)); return port; } diff --git a/test/test_tracker.cpp b/test/test_tracker.cpp index fee60960a..c5c028a89 100644 --- a/test/test_tracker.cpp +++ b/test/test_tracker.cpp @@ -426,7 +426,7 @@ TORRENT_TEST(udp_tracker_v6) TORRENT_TEST(http_peers) { - int http_port = start_web_server(); + int const http_port = start_web_server(); settings_pack pack = settings(); pack.set_bool(settings_pack::announce_to_all_trackers, true); @@ -445,7 +445,6 @@ TORRENT_TEST(http_peers) file.close(); char tracker_url[200]; - // and this should not be announced to (since the one before it succeeded) std::snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce" , http_port); t->add_tracker(tracker_url, 0); @@ -466,7 +465,7 @@ TORRENT_TEST(http_peers) status = h.status(); TEST_CHECK(!status.current_tracker.empty()); - TEST_CHECK(status.current_tracker == tracker_url); + TEST_EQUAL(status.current_tracker, tracker_url); // we expect to have certain peers in our peer list now // these peers are hard coded in web_server.py