Skip to content

Commit 4271ca5

Browse files
committed
Fixed client_get_timeout_test
1 parent e7a88ad commit 4271ca5

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

libs/network/test/http/client_get_timeout_test.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,23 @@
88
#include <boost/network/include/http/client.hpp>
99
#include <boost/test/unit_test.hpp>
1010
#include "client_types.hpp"
11+
#include "http_test_server.hpp"
1112

12-
namespace http = boost::network::http;
13+
struct localhost_server_fixture {
14+
localhost_server_fixture() {
15+
if (!server.start())
16+
std::cout << "Failed to start HTTP server for test!" << std::endl;
17+
}
18+
19+
~localhost_server_fixture() {
20+
if (!server.stop())
21+
std::cout << "Failed to stop HTTP server for test!" << std::endl;
22+
}
23+
24+
http_test_server server;
25+
};
26+
27+
BOOST_GLOBAL_FIXTURE(localhost_server_fixture);
1328

1429
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, client, client_types) {
1530
typename client::request request("http://localhost:12121/");
@@ -22,11 +37,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, client, client_types) {
2237
, std::exception);
2338
}
2439

25-
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_with_options, client,
26-
client_types) {
27-
typename client::request request(
28-
"http://cznic.dl.sourceforge.net/project/boost/boost/1.55.0/"
29-
"boost_1_55_0.tar.bz2");
40+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_with_options, client, client_types) {
41+
typename client::request request("http://localhost:8000/cgi-bin/sleep.py?3");
3042
typename client::response response;
3143
typename client::options options;
3244
client client_(options.timeout(1));
@@ -37,10 +49,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_with_options, client,
3749

3850
#ifdef BOOST_NETWORK_ENABLE_HTTPS
3951

40-
BOOST_AUTO_TEST_CASE_TEMPLATE(https_get_test_timeout_with_options, client,
41-
client_types) {
42-
typename client::request request(
43-
"https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.8.2.tar.bz2");
52+
BOOST_AUTO_TEST_CASE_TEMPLATE(https_get_test_timeout_with_options, client, client_types) {
53+
typename client::request request("https://localhost:8000/cgi-bin/sleep.py?3");
4454
typename client::response response;
4555
typename client::options options;
4656
client client_(options.timeout(1));

libs/network/test/http/http_test_server.hpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,20 @@ struct http_test_server {
6868

6969
// if executed from $CPP_NETLIB_HOME
7070
path server_path = base_path / "libs/network/test/server" / script_name;
71-
if (!exists(server_path)) {
72-
// if executed from $CPP_NETLIB_HOME/libs/network/test
73-
server_path = base_path / "server" / script_name;
74-
if (!exists(server_path)) return path();
75-
}
71+
if (exists(server_path))
72+
return server_path;
73+
74+
// if executed from $CPP_NETLIB_HOME/libs/network/test
75+
server_path = base_path / "server" / script_name;
76+
if (exists(server_path))
77+
return server_path;
78+
79+
// if executed from $CPP_NETLIB_HOME/libs/network/test/*
80+
server_path = base_path / "../server" / script_name;
81+
if (exists(server_path))
82+
return server_path;
7683

77-
return server_path;
84+
return path();
7885
}
7986

8087
script_handle_t launch_python_script(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/python
2+
import os, sys, time
3+
4+
if os.environ.has_key("QUERY_STRING") and os.environ["QUERY_STRING"].isdigit():
5+
time.sleep(int(os.environ["QUERY_STRING"]))
6+
7+
sys.stdout.write( "HTTP/1.0 200\r\n" )
8+
sys.stdout.write( "\r\n" )

0 commit comments

Comments
 (0)