From: Tobias Brunner Date: Fri, 9 May 2014 16:44:17 +0000 (+0200) Subject: unit-tests: Allow some HTTP write operations to fail X-Git-Tag: 5.2.0dr5~36^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=350c1dead93d2db0d439bdfdb30a89e599d55660;p=thirdparty%2Fstrongswan.git unit-tests: Allow some HTTP write operations to fail Because CURLOPT_FAILONERROR is enabled in the curl plugin an error code will often (not always) cause the client to close the TCP connection before the server has written the complete response. --- diff --git a/src/libstrongswan/tests/suites/test_fetch_http.c b/src/libstrongswan/tests/suites/test_fetch_http.c index eeef3587cb..42743c7872 100644 --- a/src/libstrongswan/tests/suites/test_fetch_http.c +++ b/src/libstrongswan/tests/suites/test_fetch_http.c @@ -159,25 +159,30 @@ static bool servicing(void *data, stream_t *stream) /* response headers */ snprintf(buf, sizeof(buf), "HTTP/1.%u %u OK\r\n", test->minor, test->code); ck_assert(stream->write_all(stream, buf, strlen(buf))); + + /* if the response code indicates an error the following write operations + * might fail because the client already terminated the TCP connection */ +#define may_fail(test, op) ck_assert(op || !HTTP_SUCCESS(test->code)) + t = time(NULL); gmtime_r(&t, &tm); strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z", &tm); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Server: strongSwan unit test\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); /* rest of response headers */ snprintf(buf, sizeof(buf), "Content-Type: text/plain\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Content-Length: %u\r\n", test->res_len); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Connection: close\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); /* response body */ - ck_assert(stream->write_all(stream, test->res, test->res_len)); + may_fail(test, stream->write_all(stream, test->res, test->res_len)); return FALSE; }