Skip to content

Commit 8a3e5d8

Browse files
committed
[http] add unix socket test
Open random unix socket and try communication with curl. Require minimum curl 7.50
1 parent c20581d commit 8a3e5d8

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

net/http/test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ execute_process(
3434
# curl introduce support from 8.11 but it works reliably only with 8.18
3535
if(CURL_CLI_OUTPUT MATCHES "curl ([0-9]+\\.[0-9]+\\.[0-9]+)")
3636
set(CURL_CLI_VERSION "${CMAKE_MATCH_1}")
37-
message(STATUS "Find curl ${CURL_CLI_VERSION} for http server tests")
37+
message(STATUS "Found curl ${CURL_CLI_VERSION} for http server tests")
38+
if(CURL_CLI_VERSION VERSION_GREATER_EQUAL "7.50.0")
39+
ROOT_ADD_GTEST(testUnixSocket test_xsocket.cxx LIBRARIES RHTTP RHTTPSniff Hist)
40+
endif()
3841
if(CURL_CLI_VERSION VERSION_GREATER_EQUAL "8.18.0")
3942
ROOT_ADD_GTEST(testWebSocket test_websocket.cxx LIBRARIES RHTTP Hist)
4043
endif()

net/http/test/test_xsocket.cxx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "gtest/gtest.h"
2+
3+
#include <string>
4+
#include <fstream>
5+
6+
#include "THttpServer.h"
7+
#include "TROOT.h"
8+
9+
#include "TSystem.h"
10+
#include "TNamed.h"
11+
#include "TRandom.h"
12+
13+
#include "ROOT/TestSupport.hxx"
14+
15+
16+
#include "./test_suite.cxx"
17+
18+
// main http server
19+
TEST(THttpServer, main)
20+
{
21+
THttpServer serv("");
22+
23+
TString fname;
24+
Bool_t create = kFALSE;
25+
26+
for (Int_t ntry = 0; ntry < 10; ++ntry) {
27+
fname = "root_test_";
28+
auto f = gSystem->TempFileName(fname, nullptr, ".socket");
29+
if (!f)
30+
continue;
31+
fclose(f);
32+
33+
EXPECT_EQ(fname[0], '/') << "first symbol in temporary file must be slash";
34+
create = serv.CreateEngine("socket:" + fname + "?socket_mode=0700");
35+
36+
if (create)
37+
break;
38+
39+
gSystem->Unlink(fname);
40+
}
41+
42+
EXPECT_EQ(create, kTRUE) << "create unix socket";
43+
44+
if (!create)
45+
return;
46+
47+
server_hash = fname.Hash(); // dummy number for file suffix
48+
unix_socket = "--unix-socket " + fname; // curl argument
49+
server_url = "http://localhost"; // dummy host name for curl
50+
51+
test_suite(serv);
52+
}

0 commit comments

Comments
 (0)