master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "unitcheck.h"
25#include "urldata.h"
26#include "multiif.h"
28#define T3230_TIMER_CALLS 6
30struct t3230_timer_ctx {
31 long timeout_ms[T3230_TIMER_CALLS];
32 size_t count;
33};
35static int t3230_timer_cb(CURLM *multi, long timeout_ms, void *userp)
36{
37 struct t3230_timer_ctx *ctx = userp;
38 (void)multi;
40 if(ctx->count < CURL_ARRAYSIZE(ctx->timeout_ms))
41 ctx->timeout_ms[ctx->count] = timeout_ms;
42 ++ctx->count;
43 return 0;
44}
46static CURLcode t3230_setup(void)
47{
48 CURLcode result = CURLE_OK;
49 global_init(CURL_GLOBAL_ALL);
50 return result;
51}
53static void t3230_test_timer_updates(void)
54{
55 CURLM *handle = curl_multi_init();
56 struct Curl_multi *multi = handle;
57 struct t3230_timer_ctx ctx;
58 struct curltime now;
59 timediff_t expire_offset_us;
60 CURLMcode mresult;
61 int running;
63 memset(&ctx, 0, sizeof(ctx));
64 if(!multi) {
65 fail("multi handle creation failed");
66 return;
67 }
69 mresult = curl_multi_setopt(handle, CURLMOPT_TIMERDATA, &ctx);
70 fail_unless(mresult == CURLM_OK, "setting timer data failed");
71 mresult = curl_multi_setopt(handle, CURLMOPT_TIMERFUNCTION,
72 t3230_timer_cb);
73 fail_unless(mresult == CURLM_OK, "setting timer callback failed");
75 fail_unless(Curl_update_timer(multi) == CURLM_OK,
76 "initial timer update failed");
77 fail_unless(!ctx.count, "callback invoked without a timeout");
78 fail_unless(!multi->last_timeout_set, "initial timer marked as set");
80 now = curlx_now();
81 Curl_expire_set(multi->admin, EXPIRE_TIMEOUT, 600000, &now);
82 fail_unless(Curl_update_timer(multi) == CURLM_OK,
83 "setting timer failed");
84 fail_unless(ctx.count == 1, "setting timer did not invoke callback");
85 fail_unless(multi->last_timeout_set, "timer not marked as set");
87 Curl_expire_set(multi->admin, EXPIRE_TIMEOUT, 1200000, &now);
88 fail_unless(Curl_update_timer(multi) == CURLM_OK,
89 "replacing timer failed");
90 fail_unless(ctx.count == 2, "replacing timer did not invoke callback");
92 fail_unless(Curl_update_timer(multi) == CURLM_OK,
93 "unchanged timer update failed");
94 fail_unless(ctx.count == 2, "unchanged timer invoked callback");
96 expire_offset_us = multi->last_expire_offset_us;
97 mresult = curl_multi_socket_action(handle, CURL_SOCKET_TIMEOUT, 0, &running);
98 fail_unless(mresult == CURLM_OK, "forced timer refresh failed");
99 fail_unless(ctx.count == 3, "timer refresh did not invoke callback");
100 fail_unless(multi->last_expire_offset_us == expire_offset_us,
101 "timer refresh changed expiry offset");
102 fail_unless(multi->last_timeout_set, "refreshed timer not marked as set");
104 Curl_expire_clear_all(multi->admin);
105 fail_unless(Curl_update_timer(multi) == CURLM_OK,
106 "timer clear update failed");
107 fail_unless(ctx.count == 4, "clearing timer did not invoke callback");
108 fail_unless(!multi->last_timeout_set, "cleared timer marked as set");
109 fail_unless(Curl_update_timer(multi) == CURLM_OK,
110 "repeated timer clear update failed");
112 Curl_multi_mark_dirty(multi->admin);
113 fail_unless(Curl_update_timer(multi) == CURLM_OK,
114 "zero timer update failed");
115 fail_unless(multi->last_timeout_set, "zero timer not marked as set");
116 Curl_multi_clear_dirty(multi->admin);
117 fail_unless(Curl_update_timer(multi) == CURLM_OK,
118 "clearing zero timer failed");
119 fail_unless(!multi->last_timeout_set, "zero timer clear left timer set");
121 fail_unless(ctx.count == T3230_TIMER_CALLS, "wrong timer callback count");
122 fail_unless(ctx.timeout_ms[0] >= 0, "wrong initial timeout");
123 fail_unless(ctx.timeout_ms[1] > ctx.timeout_ms[0],
124 "wrong replacement timeout");
125 fail_unless(ctx.timeout_ms[2] >= 0, "wrong refreshed timeout");
126 fail_unless(ctx.timeout_ms[3] == -1, "wrong cleared timeout");
127 fail_unless(ctx.timeout_ms[4] == 0, "wrong zero timeout");
128 fail_unless(ctx.timeout_ms[5] == -1, "wrong zero timeout clear");
130 curl_multi_cleanup(handle);
131}
133static int t3230_failing_timer_cb(CURLM *multi, long timeout_ms, void *userp)
134{
135 (void)multi;
136 (void)timeout_ms;
137 (void)userp;
138 return -1;
139}
141/* a handle that curl_multi_add_handle() fails to add is not counted */
142static void t3230_test_add_handle_timer_failure(void)
143{
144 CURLM *multi = curl_multi_init();
145 CURL *curl = curl_easy_init();
146 curl_off_t running = -1;
147 curl_off_t current = -1;
148 CURLMcode mresult;
150 if(!multi || !curl) {
151 fail("handle creation failed");
152 goto out;
153 }
155 mresult = curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION,
156 t3230_failing_timer_cb);
157 fail_unless(mresult == CURLM_OK, "setting timer callback failed");
159 mresult = curl_multi_add_handle(multi, curl);
160 fail_unless(mresult == CURLM_ABORTED_BY_CALLBACK,
161 "add_handle did not report the timer callback failure");
163 fail_unless(!curl_multi_get_offt(multi, CURLMINFO_XFERS_RUNNING, &running),
164 "getting running transfers failed");
165 fail_unless(!curl_multi_get_offt(multi, CURLMINFO_XFERS_CURRENT, ¤t),
166 "getting current transfers failed");
167 fail_unless(running == 0, "failed add counted as running");
168 fail_unless(current == 0, "failed add counted as current");
170out:
171 curl_multi_cleanup(multi);
172 curl_easy_cleanup(curl);
173}
175/* curl_multi_socket_all() returns the timer callback failure */
176static void t3230_test_socket_all_timer_failure(void)
177{
178 CURLM *handle = curl_multi_init();
179 struct Curl_multi *multi = handle;
180 struct curltime now;
181 CURLMcode mresult;
182 int running;
184 if(!multi) {
185 fail("multi handle creation failed");
186 return;
187 }
189 mresult = curl_multi_setopt(handle, CURLMOPT_TIMERFUNCTION,
190 t3230_failing_timer_cb);
191 fail_unless(mresult == CURLM_OK, "setting timer callback failed");
193 now = curlx_now();
194 Curl_expire_set(multi->admin, EXPIRE_TIMEOUT, 600000, &now);
195 mresult = curl_multi_socket_all(handle, &running);
196 fail_unless(mresult == CURLM_ABORTED_BY_CALLBACK,
197 "socket_all did not report the timer callback failure");
199 curl_multi_cleanup(handle);
200}
202static CURLcode test_unit3230(const char *arg)
203{
204 UNITTEST_BEGIN(t3230_setup())
206 t3230_test_timer_updates();
207 t3230_test_add_handle_timer_failure();
208 t3230_test_socket_all_timer_failure();
210 UNITTEST_END(curl_global_cleanup())
211}
Diagnostics4 git calls · 967 ms
CallStatusSizeTime0967 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=23 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.1 KiB942 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=942 git.response.bytes=2119 git.response.cache=MISS git.response.duration_ms=942 git.fetch.wants=065a65b32f57930f3357db91885bd1739a42dab7 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2119 git.pkt.payload.max=2098 git.sideband.band1.bytes=2097 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1fe77be5ea9c0
- Request
- 00eeaf6e…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format