From fbd33b33dbc222c03ccf6bc894915108d6f94e4b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 26 Dec 2019 18:09:35 -0800 Subject: fixes #940 httpclient Timeout can succeed in cloud --- tests/httpclient.c | 47 +++++++++++++++++++++++++++++------------------ 1 file 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 #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; -- cgit v1.2.3-70-g09d2