Skip to content

RedirectFromPageWithContentIP6 test locks if CONFIG_IPV6 is disabled in the Linux kernel #1053

Closed
@Tachi107

Description

When the Linux kernel is built without IPV6 support, the RedirectFromPageWithContentIP6 test never completes, as it doesn't go past while(!svr.is_running()) (line 974).

cpp-httplib/test/test.cc

Lines 955 to 1013 in 3c52238

TEST(RedirectFromPageWithContentIP6, Redirect) {
Server svr;
svr.Get("/1", [&](const Request & /*req*/, Response &res) {
res.set_content("___", "text/plain");
// res.set_redirect("/2");
res.set_redirect("http://[::1]:1234/2");
});
svr.Get("/2", [&](const Request &req, Response &res) {
auto host_header = req.headers.find("Host");
ASSERT_TRUE(host_header != req.headers.end());
EXPECT_EQ("[::1]:1234", host_header->second);
res.set_content("Hello World!", "text/plain");
});
auto th = std::thread([&]() { svr.listen("::1", 1234); });
while (!svr.is_running()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
// Give GET time to get a few messages.
std::this_thread::sleep_for(std::chrono::seconds(1));
{
Client cli("http://[::1]:1234");
cli.set_follow_location(true);
std::string body;
auto res = cli.Get("/1", [&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
EXPECT_EQ("Hello World!", body);
}
{
Client cli("http://[::1]:1234");
std::string body;
auto res = cli.Get("/1", [&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
ASSERT_TRUE(res);
EXPECT_EQ(302, res->status);
EXPECT_EQ("___", body);
}
svr.stop();
th.join();
ASSERT_FALSE(svr.is_running());
}

I believe that this happens because when IPV6 support isn't available svr.listen("::1", 1234) never actually starts anything, so the condition !svr.is_running() will always remain true.

A possible solution would be to only wait for a few seconds, and if svr does not start abort the test

Edit: Since Server::listen() returns false on failure, it may be more appropriate to do something like ASSERT_TRUE(svr.listen("::1", 1234))

Edit2: ASSERT_TRUE in the other thread doesn't work

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions