summaryrefslogtreecommitdiff
path: root/tests/httpclient.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2019-12-26 18:09:35 -0800
committerGarrett D'Amore <garrett@damore.org>2019-12-26 19:43:35 -0800
commitfbd33b33dbc222c03ccf6bc894915108d6f94e4b (patch)
tree08c49f4ae1a228ac96c2c93e35bf77f7318be3dd /tests/httpclient.c
parenta31df988bb59e438e0eca9f7fb057a2c8ff7b54b (diff)
downloadnng-fbd33b33dbc222c03ccf6bc894915108d6f94e4b.tar.gz
nng-fbd33b33dbc222c03ccf6bc894915108d6f94e4b.tar.bz2
nng-fbd33b33dbc222c03ccf6bc894915108d6f94e4b.zip
fixes #940 httpclient Timeout can succeed in cloud
Diffstat (limited to 'tests/httpclient.c')
-rw-r--r--tests/httpclient.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/tests/httpclient.c b/tests/httpclient.c
index b804d666..3e6351be 100644
--- a/tests/httpclient.c
+++ b/tests/httpclient.c
@@ -10,7 +10,6 @@
// Basic HTTP client tests.
-
#ifndef _WIN32
#include <arpa/inet.h>
#endif
@@ -157,23 +156,6 @@ TestMain("HTTP Client", {
So(memcmp(digest, example_sum, 20) == 0);
});
- Convey("Timeout works", {
- nng_http_req *req;
- nng_http_res *res;
-
- So(nng_http_req_alloc(&req, url) == 0);
- So(nng_http_res_alloc(&res) == 0);
- Reset({
- nng_http_req_free(req);
- nng_http_res_free(res);
- });
-
- nng_aio_set_timeout(aio, 1); // 1 ms, should timeout!
- nng_http_client_transact(cli, req, res, aio);
- nng_aio_wait(aio);
- So(nng_aio_result(aio) == NNG_ETIMEDOUT);
- });
-
Convey("Connection reuse works", {
nng_http_req * req;
nng_http_res * res1;
@@ -218,6 +200,35 @@ TestMain("HTTP Client", {
});
});
+ Convey("Client times out", {
+ nng_aio * aio;
+ nng_http_client *cli;
+ nng_url * url;
+ nng_http_req * req;
+ nng_http_res * res;
+
+ So(nng_aio_alloc(&aio, NULL, NULL) == 0);
+
+ So(nng_url_parse(&url, "http://httpbin.org/delay/30") == 0);
+
+ So(nng_http_client_alloc(&cli, url) == 0);
+ So(nng_http_req_alloc(&req, url) == 0);
+ So(nng_http_res_alloc(&res) == 0);
+
+ Reset({
+ nng_http_client_free(cli);
+ nng_url_free(url);
+ nng_aio_free(aio);
+ nng_http_req_free(req);
+ nng_http_res_free(res);
+ });
+ nng_aio_set_timeout(aio, 10); // 10 msec timeout
+
+ nng_http_client_transact(cli, req, res, aio);
+ nng_aio_wait(aio);
+ So(nng_aio_result(aio) == NNG_ETIMEDOUT);
+ });
+
Convey("Given a client (chunked)", {
nng_aio * aio;
nng_http_client *cli;