Skip to content

Commit

Permalink
Allow multiple seed containers when testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zitrax committed Dec 2, 2024
1 parent 0626073 commit 1a9c071
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions tests/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace zit {
class Process {
public:
Process(const std::string& name,
std::vector<const char*> argv,
std::vector<std::string> argv,
const char* cwd = nullptr,
std::vector<const char*> stop_cmd = {});
std::vector<std::string> stop_cmd = {});

// Since this should be created and deleted only once
// forbid copying and assignment.
Expand Down Expand Up @@ -74,7 +74,7 @@ class Process {
private:
pid_t m_pid;
std::string m_name;
std::vector<const char*> m_stop_cmd;
std::vector<std::string> m_stop_cmd;
};

} // namespace zit
4 changes: 2 additions & 2 deletions tests/process_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace zit {
using namespace std;

Process::Process(const string& name,
vector<const char*> argv,
vector<string> argv,
const char* cwd,
vector<const char*> stop_cmd)
vector<string> stop_cmd)
: m_pid(0), m_name(name), m_stop_cmd(move(stop_cmd)) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
Expand Down
29 changes: 14 additions & 15 deletions tests/test_integrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace std::string_literals;
using namespace zit;
namespace fs = std::filesystem;

//constexpr auto TEST_BIND_ADDRESS{"192.168.0.18"};
// constexpr auto TEST_BIND_ADDRESS{"192.168.0.18"};

class TestConfig : public zit::Config {
public:
Expand All @@ -38,7 +38,7 @@ class TestConfig : public zit::Config {
// m_bool_settings[zit::BoolSetting::INITIATE_PEER_CONNECTIONS] = false;

// Transmission does not want to connect to localhost, so trick it
//m_string_settings[zit::StringSetting::BIND_ADDRESS] = TEST_BIND_ADDRESS;
// m_string_settings[zit::StringSetting::BIND_ADDRESS] = TEST_BIND_ADDRESS;
}

void set(IntSetting setting, int val) { m_int_settings[setting] = val; }
Expand All @@ -63,7 +63,7 @@ auto start_tracker(const fs::path& data_dir) {
auto tracker =
Process("tracker",
{"docker", "run", "--rm", "--name", "zit-opentracker", "--volume",
fmt::format("{}:{}", data_dir.generic_string(), "/data").c_str(),
fmt::format("{}:{}", data_dir.generic_string(), "/data"),
//"--network", "host",
"--publish", "8000:8000", "opentracker", "-p", "8000",
// The default opentracker build seem to be compiled in closed
Expand All @@ -89,26 +89,25 @@ auto start_seeder(const fs::path& data_dir,
constexpr auto* container_data_dir = "/data";
constexpr auto* container_torrent_dir = "/torrents";

static int seeder_count{0};
const auto container_name = fmt::format("zit-webtorrent-{}", seeder_count++);

const auto port = std::to_string(webtorrent_seeding_port);
return Process(
name,
{"docker", "run", "--rm", "--name", "zit-webtorrent", "--publish",
fmt::format("{}:{}", port, port).c_str(), //"--network", "host",
"--volume",
fmt::format("{}:{}", data_dir.generic_string(), container_data_dir)
.c_str(),
{"docker", "run", "--rm", "--name", container_name, "--publish",
fmt::format("{}:{}", port, port), "--volume",
fmt::format("{}:{}", data_dir.generic_string(), container_data_dir),
"--volume",
fmt::format("{}:{}", torrent_file.parent_path().generic_string(),
container_torrent_dir)
.c_str(),
container_torrent_dir),
"webtorrent", "seed",
// Torrent file
fmt::format("{}/{}", container_torrent_dir, torrent_file.filename())
.c_str(),
fmt::format("{}/{}", container_torrent_dir, torrent_file.filename()),
"--out", container_data_dir, "--torrent-port",
std::to_string(webtorrent_seeding_port++).c_str(), "--port",
std::to_string(webtorrent_http_port++).c_str(), "--keep-seeding"},
nullptr, {"docker", "stop", "zit-webtorrent"});
std::to_string(webtorrent_seeding_port++), "--port",
std::to_string(webtorrent_http_port++), "--keep-seeding"},
nullptr, {"docker", "stop", container_name});
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/test_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ class UDP : public ::testing::Test {
(std::filesystem::path(DATA_DIR) / ".." / "udp_server.py")
.lexically_normal();
echo_server = std::make_unique<zit::Process>(
"udp_echo", std::vector<const char*>{"python", udp_server_path.generic_string().c_str(),
std::to_string(m_port).c_str()});
"udp_echo",
std::vector<std::string>{"python", udp_server_path.generic_string(),
std::to_string(m_port)});
}

void TearDown() override {
Expand Down Expand Up @@ -176,4 +177,3 @@ TEST_F(UDP, request_named_host) {
const auto reply = Net::udpRequest(url, message);
ASSERT_THAT(message, ElementsAreArray(reply));
}

0 comments on commit 1a9c071

Please sign in to comment.