|
| 1 | +project(lws-minimal-http-client-timeout-h3 C) |
| 2 | +cmake_minimum_required(VERSION 3.10) |
| 3 | +find_package(libwebsockets CONFIG REQUIRED) |
| 4 | +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) |
| 5 | +include(CheckCSourceCompiles) |
| 6 | +include(LwsCheckRequirements) |
| 7 | + |
| 8 | +set(SAMP lws-minimal-http-client-timeout-h3) |
| 9 | +set(SRCS minimal-http-client-timeout-h3.c) |
| 10 | + |
| 11 | +set(requirements 1) |
| 12 | +require_lws_config(LWS_ROLE_QUIC 1 requirements) |
| 13 | +require_lws_config(LWS_WITH_HTTP3 1 requirements) |
| 14 | +require_lws_config(LWS_WITH_CLIENT 1 requirements) |
| 15 | +require_lws_config(LWS_WITH_SERVER 1 requirements) |
| 16 | + |
| 17 | +if (requirements) |
| 18 | + add_executable(${SAMP} ${SRCS}) |
| 19 | + |
| 20 | + if (websockets_shared) |
| 21 | + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) |
| 22 | + add_dependencies(${SAMP} websockets_shared) |
| 23 | + else() |
| 24 | + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) |
| 25 | + endif() |
| 26 | + |
| 27 | + if (LWS_WITH_MINIMAL_EXAMPLES) |
| 28 | + # |
| 29 | + # The test starts the blackhole QUIC server (-s) on a free port, |
| 30 | + # gives it a moment to bind, runs the client against it, then |
| 31 | + # kills the server. The client's success condition is that it |
| 32 | + # times out awaiting the reply (the server never answers), which |
| 33 | + # exercises the H3 client reply timeout. We bundle server + |
| 34 | + # client into a single ctest command with a tiny inline shell |
| 35 | + # wrapper so the test is self-contained and does not depend on |
| 36 | + # netstat/lsof-based port detection helpers. |
| 37 | + # |
| 38 | + # Expected exit codes: server (-s) always returns 0; the client |
| 39 | + # returns 0 if it saw the timeout and non-zero otherwise, so the |
| 40 | + # client exit code is the test result. |
| 41 | + lws_get_free_port(PORT_H3TO) |
| 42 | + |
| 43 | + add_test(NAME h3to COMMAND sh -c |
| 44 | + "$<TARGET_FILE:${SAMP}> -s -p ${PORT_H3TO} -d1039 2>/dev/null & SRV=$!; sleep 2; $<TARGET_FILE:${SAMP}> -p ${PORT_H3TO} -d1039; RC=$?; kill $SRV 2>/dev/null; wait $SRV 2>/dev/null; exit $RC") |
| 45 | + set_tests_properties(h3to PROPERTIES |
| 46 | + WORKING_DIRECTORY . |
| 47 | + TIMEOUT 40) |
| 48 | + endif() |
| 49 | +endif() |
0 commit comments