diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2023-05-13 17:11:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-13 17:11:56 +0100 |
| commit | 9d41a3fd694d983ade53fb602a58f6df25ce0656 (patch) | |
| tree | 73fb6759a3138023f85654e38dcac1fb9cc4c7ad /tests | |
| parent | 905e4d19c2c401cef3964c2e28bf64b0dad77331 (diff) | |
| parent | 8f695c806bac2b044f102c55b802e44f2d30ca01 (diff) | |
| download | libgit2-9d41a3fd694d983ade53fb602a58f6df25ce0656.tar.gz | |
Merge pull request #6535 from libgit2/ethomson/timeouts
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/clar/clar_libgit2_timer.c | 8 | ||||
| -rw-r--r-- | tests/clar/clar_libgit2_timer.h | 10 | ||||
| -rw-r--r-- | tests/clar/clar_libgit2_trace.c | 2 | ||||
| -rw-r--r-- | tests/libgit2/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | tests/libgit2/network/matchhost.c | 13 | ||||
| -rw-r--r-- | tests/libgit2/online/clone.c | 76 | ||||
| -rw-r--r-- | tests/util/hostname.c | 13 | ||||
| -rw-r--r-- | tests/util/url/joinpath.c | 1 | ||||
| -rw-r--r-- | tests/util/url/redirect.c | 1 |
9 files changed, 100 insertions, 26 deletions
diff --git a/tests/clar/clar_libgit2_timer.c b/tests/clar/clar_libgit2_timer.c index 2330f9351..6c75413be 100644 --- a/tests/clar/clar_libgit2_timer.c +++ b/tests/clar/clar_libgit2_timer.c @@ -8,23 +8,23 @@ void cl_perf_timer__init(cl_perf_timer *t) void cl_perf_timer__start(cl_perf_timer *t) { - t->time_started = git__timer(); + t->time_started = git_time_monotonic(); } void cl_perf_timer__stop(cl_perf_timer *t) { - double time_now = git__timer(); + uint64_t time_now = git_time_monotonic(); t->last = time_now - t->time_started; t->sum += t->last; } -double cl_perf_timer__last(const cl_perf_timer *t) +uint64_t cl_perf_timer__last(const cl_perf_timer *t) { return t->last; } -double cl_perf_timer__sum(const cl_perf_timer *t) +uint64_t cl_perf_timer__sum(const cl_perf_timer *t) { return t->sum; } diff --git a/tests/clar/clar_libgit2_timer.h b/tests/clar/clar_libgit2_timer.h index 7571a52e9..887067278 100644 --- a/tests/clar/clar_libgit2_timer.h +++ b/tests/clar/clar_libgit2_timer.h @@ -4,13 +4,13 @@ struct cl_perf_timer { /* cumulative running time across all start..stop intervals */ - double sum; + uint64_t sum; /* value of last start..stop interval */ - double last; + uint64_t last; /* clock value at start */ - double time_started; + uint64_t time_started; }; #define CL_PERF_TIMER_INIT {0} @@ -24,12 +24,12 @@ void cl_perf_timer__stop(cl_perf_timer *t); /** * return value of last start..stop interval in seconds. */ -double cl_perf_timer__last(const cl_perf_timer *t); +uint64_t cl_perf_timer__last(const cl_perf_timer *t); /** * return cumulative running time across all start..stop * intervals in seconds. */ -double cl_perf_timer__sum(const cl_perf_timer *t); +uint64_t cl_perf_timer__sum(const cl_perf_timer *t); #endif /* __CLAR_LIBGIT2_TIMER__ */ diff --git a/tests/clar/clar_libgit2_trace.c b/tests/clar/clar_libgit2_trace.c index ebb0f41dd..814a5fa9e 100644 --- a/tests/clar/clar_libgit2_trace.c +++ b/tests/clar/clar_libgit2_trace.c @@ -197,7 +197,7 @@ static void _cl_trace_cb__event_handler( case CL_TRACE__TEST__END: cl_perf_timer__stop(&s_timer_test); - git_trace(GIT_TRACE_TRACE, "%s::%s: End Test (%.3f %.3f)", suite_name, test_name, + git_trace(GIT_TRACE_TRACE, "%s::%s: End Test (%" PRIuZ " %" PRIuZ ")", suite_name, test_name, cl_perf_timer__last(&s_timer_run), cl_perf_timer__last(&s_timer_test)); break; diff --git a/tests/libgit2/CMakeLists.txt b/tests/libgit2/CMakeLists.txt index 866122d1c..af70f55a7 100644 --- a/tests/libgit2/CMakeLists.txt +++ b/tests/libgit2/CMakeLists.txt @@ -65,7 +65,7 @@ endif() include(AddClarTest) add_clar_test(libgit2_tests offline -v -xonline) -add_clar_test(libgit2_tests invasive -v -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root) +add_clar_test(libgit2_tests invasive -v -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root -sonline::clone::connect_timeout_default) add_clar_test(libgit2_tests online -v -sonline -xonline::customcert) add_clar_test(libgit2_tests online_customcert -v -sonline::customcert) add_clar_test(libgit2_tests gitdaemon -v -sonline::push) diff --git a/tests/libgit2/network/matchhost.c b/tests/libgit2/network/matchhost.c deleted file mode 100644 index 3100dc21d..000000000 --- a/tests/libgit2/network/matchhost.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "clar_libgit2.h" -#include "netops.h" - -void test_network_matchhost__match(void) -{ - cl_git_pass(gitno__match_host("*.example.org", "www.example.org")); - cl_git_pass(gitno__match_host("*.foo.example.org", "www.foo.example.org")); - cl_git_fail(gitno__match_host("*.foo.example.org", "foo.example.org")); - cl_git_fail(gitno__match_host("*.foo.example.org", "www.example.org")); - cl_git_fail(gitno__match_host("*.example.org", "example.org")); - cl_git_fail(gitno__match_host("*.example.org", "www.foo.example.org")); - cl_git_fail(gitno__match_host("*.example.org", "blah.www.www.example.org")); -} diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c index b635739b6..dbcac50ae 100644 --- a/tests/libgit2/online/clone.c +++ b/tests/libgit2/online/clone.c @@ -35,6 +35,8 @@ static char *_remote_proxy_selfsigned = NULL; static char *_remote_expectcontinue = NULL; static char *_remote_redirect_initial = NULL; static char *_remote_redirect_subsequent = NULL; +static char *_remote_speed_timesout = NULL; +static char *_remote_speed_slow = NULL; static char *_github_ssh_pubkey = NULL; static char *_github_ssh_privkey = NULL; @@ -89,6 +91,8 @@ void test_online_clone__initialize(void) _remote_expectcontinue = cl_getenv("GITTEST_REMOTE_EXPECTCONTINUE"); _remote_redirect_initial = cl_getenv("GITTEST_REMOTE_REDIRECT_INITIAL"); _remote_redirect_subsequent = cl_getenv("GITTEST_REMOTE_REDIRECT_SUBSEQUENT"); + _remote_speed_timesout = cl_getenv("GITTEST_REMOTE_SPEED_TIMESOUT"); + _remote_speed_slow = cl_getenv("GITTEST_REMOTE_SPEED_SLOW"); _github_ssh_pubkey = cl_getenv("GITTEST_GITHUB_SSH_PUBKEY"); _github_ssh_privkey = cl_getenv("GITTEST_GITHUB_SSH_KEY"); @@ -128,6 +132,8 @@ void test_online_clone__cleanup(void) git__free(_remote_expectcontinue); git__free(_remote_redirect_initial); git__free(_remote_redirect_subsequent); + git__free(_remote_speed_timesout); + git__free(_remote_speed_slow); git__free(_github_ssh_pubkey); git__free(_github_ssh_privkey); @@ -145,6 +151,8 @@ void test_online_clone__cleanup(void) } git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, NULL, NULL); + git_libgit2_opts(GIT_OPT_SET_SERVER_TIMEOUT, 0); + git_libgit2_opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, 0); } void test_online_clone__network_full(void) @@ -1207,3 +1215,71 @@ void test_online_clone__sha256(void) git_reference_free(head); #endif } + +void test_online_clone__connect_timeout_configurable(void) +{ +#ifdef GIT_WINHTTP + cl_skip(); +#else + uint64_t start, finish; + + start = git_time_monotonic(); + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, 1)); + cl_git_fail(git_clone(&g_repo, "http://www.google.com:8000/", "./timedout", NULL)); + cl_assert(git_error_last() && strstr(git_error_last()->message, "timed out")); + + finish = git_time_monotonic(); + + cl_assert(finish - start < 1000); +#endif +} + +void test_online_clone__connect_timeout_default(void) +{ +#ifdef GIT_WINHTTP + cl_skip(); +#else + /* This test takes ~ 75 seconds on Unix. */ + if (!cl_is_env_set("GITTEST_INVASIVE_SPEED")) + cl_skip(); + + /* + * Use a host/port pair that blackholes packets and does not + * send an RST. + */ + cl_git_fail_with(GIT_TIMEOUT, git_clone(&g_repo, "http://www.google.com:8000/", "./refused", NULL)); + cl_assert(git_error_last() && strstr(git_error_last()->message, "timed out")); +#endif +} + +void test_online_clone__timeout_configurable_times_out(void) +{ +#ifdef GIT_WINHTTP + cl_skip(); +#else + git_repository *failed_repo; + + if (!_remote_speed_timesout) + cl_skip(); + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SERVER_TIMEOUT, 1000)); + + cl_git_fail_with(GIT_TIMEOUT, git_clone(&failed_repo, _remote_speed_timesout, "./timedout", NULL)); + cl_assert(git_error_last() && strstr(git_error_last()->message, "timed out")); +#endif +} + +void test_online_clone__timeout_configurable_succeeds_slowly(void) +{ +#ifdef GIT_WINHTTP + cl_skip(); +#else + if (!_remote_speed_slow) + cl_skip(); + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SERVER_TIMEOUT, 1000)); + + cl_git_pass(git_clone(&g_repo, _remote_speed_slow, "./slow-but-successful", NULL)); +#endif +} diff --git a/tests/util/hostname.c b/tests/util/hostname.c new file mode 100644 index 000000000..5d8bfe2ac --- /dev/null +++ b/tests/util/hostname.c @@ -0,0 +1,13 @@ +#include "clar_libgit2.h" +#include "net.h" + +void test_hostname__matches_cert(void) +{ + cl_assert_equal_b(true, git_net_hostname_matches_cert("www.example.org", "*.example.org")); + cl_assert_equal_b(true, git_net_hostname_matches_cert("www.foo.example.org", "*.foo.example.org")); + cl_assert_equal_b(false, git_net_hostname_matches_cert("foo.example.org", "*.foo.example.org")); + cl_assert_equal_b(false, git_net_hostname_matches_cert("www.example.org", "*.foo.example.org")); + cl_assert_equal_b(false, git_net_hostname_matches_cert("example.org", "*.example.org")); + cl_assert_equal_b(false, git_net_hostname_matches_cert("www.foo.example.org", "*.example.org")); + cl_assert_equal_b(false, git_net_hostname_matches_cert("blah.www.www.example.org", "*.example.org")); +} diff --git a/tests/util/url/joinpath.c b/tests/util/url/joinpath.c index 9fc02cde4..6027093e4 100644 --- a/tests/util/url/joinpath.c +++ b/tests/util/url/joinpath.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" #include "net.h" -#include "netops.h" static git_net_url source, target; diff --git a/tests/util/url/redirect.c b/tests/util/url/redirect.c index 540177861..a6f99dcdf 100644 --- a/tests/util/url/redirect.c +++ b/tests/util/url/redirect.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" #include "net.h" -#include "netops.h" static git_net_url conndata; |
