Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16d2952

Browse files
committed
Simplifying Async Server Tests.
This commit makes the asynchronous server testswork more similarly to the synchronous tests tominimize failures and false alarms.
1 parent9e98160 commit16d2952

File tree

4 files changed

+23
-48
lines changed

4 files changed

+23
-48
lines changed

‎libs/network/test/http/server_async.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,13 @@ struct async_hello_world {
3131
static server::response_header headers[] = {
3232
{"Connection","close"}
3333
, {"Content-Type","text/plain"}
34-
, {"Server","cpp-netlib/0.9-devel"}
34+
, {"Server","cpp-netlib/0.9"}
35+
, {"Content-Length","13"}
3536
};
36-
if (request.method =="HEAD") {
37-
connection->set_status(server::connection::ok);
38-
connection->set_headers(boost::make_iterator_range(headers, headers+3));
39-
}else {
40-
if (request.method =="PUT" || request.method =="POST") {
41-
static std::stringbad_request("Bad Request.");
42-
server::request::headers_container_type::iterator found =
43-
boost::find_if(request.headers,is_content_length());
44-
if (found == request.headers.end()) {
45-
connection->set_status(server::connection::bad_request);
46-
connection->set_headers(boost::make_iterator_range(headers, headers+3));
47-
connection->write(bad_request);
48-
return;
49-
}
50-
}
51-
static std::stringhello_world("Hello, World!");
52-
connection->set_status(server::connection::ok);
53-
connection->set_headers(boost::make_iterator_range(headers, headers+3));
54-
connection->write(hello_world);
55-
}
37+
static std::stringhello_world("Hello, World!");
38+
connection->set_status(server::connection::ok);
39+
connection->set_headers(boost::make_iterator_range(headers, headers+4));
40+
connection->write(hello_world);
5641
}
5742
};
5843

@@ -61,7 +46,7 @@ int main(int argc, char * argv[]) {
6146
async_hello_world handler;
6247
std::string port ="8000";
6348
if (argc >1) port = argv[1];
64-
serverinstance("127.0.0.1", port, handler, thread_pool, http::_reuse_address=true);
49+
serverinstance("localhost", port, handler, thread_pool, http::_reuse_address=true);
6550
instance.run();
6651
return0;
6752
}

‎libs/network/test/http/server_async_less_copy.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,15 @@ struct async_hello_world {
3333
static server::response_header headers[] = {
3434
{"Connection","close"}
3535
, {"Content-Type","text/plain"}
36-
, {"Server","cpp-netlib/0.9-devel"}
36+
, {"Server","cpp-netlib/0.9"}
37+
, {"Content-Length","13"}
3738
};
38-
if (request.method =="HEAD") {
39-
connection->set_status(server::connection::ok);
40-
connection->set_headers(boost::make_iterator_range(headers, headers+3));
41-
}else {
42-
if (request.method =="PUT" || request.method =="POST") {
43-
static std::stringbad_request("Bad Request.");
44-
server::request::headers_container_type::iterator found =
45-
boost::find_if(request.headers,is_content_length());
46-
if (found == request.headers.end()) {
47-
connection->set_status(server::connection::bad_request);
48-
connection->set_headers(boost::make_iterator_range(headers, headers+3));
49-
connection->write(bad_request);
50-
return;
51-
}
52-
}
53-
staticcharconst * hello_world ="Hello, World!";
54-
connection->set_status(server::connection::ok);
55-
connection->set_headers(boost::make_iterator_range(headers, headers+3));
56-
std::vector<boost::asio::const_buffer> iovec;
57-
iovec.push_back(boost::asio::const_buffer(hello_world,13));
58-
connection->write(iovec,boost::bind(&async_hello_world::error,this, _1));
59-
}
39+
staticcharconst * hello_world ="Hello, World!";
40+
connection->set_status(server::connection::ok);
41+
connection->set_headers(boost::make_iterator_range(headers, headers+4));
42+
std::vector<boost::asio::const_buffer> iovec;
43+
iovec.push_back(boost::asio::const_buffer(hello_world,13));
44+
connection->write(iovec,boost::bind(&async_hello_world::error,this, _1));
6045
}
6146

6247
voiderror(boost::system::error_codeconst & ec) {
@@ -69,6 +54,7 @@ int main(int argc, char * argv[]) {
6954
async_hello_world handler;
7055
std::string port ="8000";
7156
if (argc >1) port = argv[1];
57+
std::cerr <<"Configuration: port =" << port << std::endl;
7258
serverinstance("127.0.0.1", port, handler, thread_pool, http::_reuse_address=true);
7359
instance.run();
7460
return0;

‎libs/network/test/http/server_include_inlined.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ int main(int argc, char * argv[]) {
4949
if (argc >1) port = argv[1];
5050
serverserver_("127.0.0.1", port, handler, http::_reuse_address=true);
5151
boost::threadrunner(boost::bind(&server::run, &server_));
52-
server_.stop();
53-
runner.join();
52+
try {
53+
server_.stop();
54+
runner.join();
55+
}catch (...) {
56+
/* ignore all errors*/
57+
}
5458
return EXIT_SUCCESS;
5559
}
5660

‎libs/network/test/httplib_acceptance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_status(url, method, expected, headers={}, body=''):
5858
print('Caught Exception: {0}'.format(e))
5959
status=1
6060

61-
url='http://localhost:{0}/'.format(argv[2])
61+
url='http://127.0.0.1:{0}/'.format(argv[2])
6262
test(url,'GET',expected)
6363
test(url,'DELETE',expected)
6464
# Good request case, there's a content-length header for POST

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp