]> granicus.if.org Git - libevent/commitdiff
test/regress_http: fix unix_socket test
authorAzat Khuzhin <azat@libevent.org>
Sun, 19 Sep 2021 08:07:55 +0000 (11:07 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sun, 19 Sep 2021 08:13:30 +0000 (11:13 +0300)
test/regress_http.c

index 752b5fc623848549289bc48beabe88b27cfbe4aa..24166303261217c7b6eb43167f83dc9323db61d9 100644 (file)
@@ -2279,14 +2279,20 @@ static void http_unix_socket_test(void *arg)
        struct evhttp_uri *uri = NULL;
        struct evhttp_connection *evcon = NULL;
        struct evhttp_request *req;
+       struct evhttp *myhttp;
+       char tmp_sock_path[512];
+       char uri_loc[1024];
 
-       struct evhttp *myhttp = evhttp_new(data->base);
+       // Avoid overlap with parallel runs
+       evutil_snprintf(tmp_sock_path, sizeof(tmp_sock_path), "/tmp/eventtmp.%i.sock", getpid());
+       evutil_snprintf(uri_loc, sizeof(uri_loc), "http://unix:%s:/?arg=val", tmp_sock_path);
 
-       tt_assert(!evhttp_bind_unixsocket(myhttp, "foo"));
+       myhttp = evhttp_new(data->base);
+       tt_assert(!evhttp_bind_unixsocket(myhttp, tmp_sock_path));
 
        evhttp_set_cb(myhttp, "/", http_dispatcher_cb, data->base);
 
-       uri = evhttp_uri_parse_with_flags("http://unix:./foo:/?arg=val", EVHTTP_URI_UNIX_SOCKET);
+       uri = evhttp_uri_parse_with_flags(uri_loc, EVHTTP_URI_UNIX_SOCKET);
        tt_assert(uri);
 
        evcon = evhttp_connection_base_bufferevent_unix_new(data->base, NULL, evhttp_uri_get_unixsocket(uri));
@@ -2314,7 +2320,10 @@ static void http_unix_socket_test(void *arg)
                evhttp_free(myhttp);
        if (uri)
                evhttp_uri_free(uri);
-       unlink("foo");
+
+       /* Does mkstemp() succeed? */
+       if (!strstr(tmp_sock_path, "XXXXXX"))
+               unlink(tmp_sock_path);
 }
 #endif