diff --git a/src/test/pull_hf_model_test.cpp b/src/test/pull_hf_model_test.cpp index 1fbd0798f6..08927e92d1 100644 --- a/src/test/pull_hf_model_test.cpp +++ b/src/test/pull_hf_model_test.cpp @@ -891,7 +891,27 @@ TEST_F(HfDownloadModelModule, TestInvalidProxyTimeout) { ConstructorEnabledConfig config; { EnvGuard eGuard; + // prepareLibgit2Opts() in hf_pull_model_module.cpp only applies the + // GIT_OPT_SET_SERVER_CONNECT_TIMEOUT option when https_proxy is empty, + // so we always clear https_proxy here. + // + // To make the timeout actually fire we need the destination to be + // unreachable. The behavior depends on the host's network setup: + // * Host originally used a proxy (https_proxy was set in the + // environment): the host is on a proxy-only network where a + // direct connection to huggingface.co will hang and hit the + // timeout. Keep the default HF_ENDPOINT. + // * Host has no proxy configured (direct internet access): a direct + // connection to huggingface.co would succeed within the 1 s + // timeout and the assertion below would fail. Redirect the clone + // to an unroutable RFC 5737 TEST-NET-1 address so the connect + // must time out. + const char* hostHttpsProxy = std::getenv("https_proxy"); + const bool hostHadProxy = (hostHttpsProxy != nullptr) && (std::string(hostHttpsProxy) != ""); eGuard.set("https_proxy", ""); + if (!hostHadProxy) { + eGuard.set("HF_ENDPOINT", "https://192.0.2.1/"); + } const std::string timeoutConnectVal = "1000"; eGuard.set(ovms::HfPullModelModule::GIT_SERVER_CONNECT_TIMEOUT_ENV, timeoutConnectVal); config.parse(arg_count, const_cast(n_argv));