]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Allow some HTTP write operations to fail
authorTobias Brunner <tobias@strongswan.org>
Fri, 9 May 2014 16:44:17 +0000 (18:44 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 19 May 2014 12:28:45 +0000 (14:28 +0200)
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.

src/libstrongswan/tests/suites/test_fetch_http.c

index eeef3587cb3425858300a7de7215eb15a5c61cc7..42743c78728b110e20d94b63be17e55bfcfbf5b4 100644 (file)
@@ -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;
 }