Skip to content

Commit 761c9b6

Browse files
jeffhostetlerderrickstolee
authored andcommitted
test-gvfs-prococol, t5799: tests for gvfs-helper
Create t/helper/test-gvfs-protocol.c and t/t5799-gvfs-helper.sh to test gvfs-helper. Create t/helper/test-gvfs-protocol.c as a stand-alone web server that speaks the GVFS Protocol [1] and serves loose objects and packfiles to clients. It is borrows heavily from the code in daemon.c. It includes a "mayhem" mode to cause various network and HTTP errors to test the retry/recovery ability of gvfs-helper. Create t/t5799-gvfs-helper.sh to test gvfs-helper. [1] https://github.com/microsoft/VFSForGit/blob/master/Protocol.md Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 32dc122 commit 761c9b6

File tree

5 files changed

+2752
-7
lines changed

5 files changed

+2752
-7
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ else
14931493
BASIC_CFLAGS += $(CURL_CFLAGS)
14941494

14951495
PROGRAM_OBJS += gvfs-helper.o
1496+
TEST_PROGRAMS_NEED_X += test-gvfs-protocol
14961497

14971498
REMOTE_CURL_PRIMARY = git-remote-http$X
14981499
REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X

contrib/buildsystems/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,20 @@ set(wrapper_scripts
10201020
set(wrapper_test_scripts
10211021
test-fake-ssh test-tool)
10221022

1023+
if(CURL_FOUND)
1024+
list(APPEND wrapper_test_scripts test-gvfs-protocol)
1025+
1026+
add_executable(test-gvfs-protocol ${CMAKE_SOURCE_DIR}/t/helper/test-gvfs-protocol.c)
1027+
target_link_libraries(test-gvfs-protocol common-main)
1028+
1029+
if(MSVC)
1030+
set_target_properties(test-gvfs-protocol
1031+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper)
1032+
set_target_properties(test-gvfs-protocol
1033+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper)
1034+
endif()
1035+
endif()
1036+
10231037

10241038
foreach(script ${wrapper_scripts})
10251039
file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)

gvfs-helper.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,8 @@ static void install_loose(struct gh__request_params *params,
18731873
/*
18741874
* We expect a loose object when we do a GET -or- when we
18751875
* do a POST with only 1 object.
1876+
*
1877+
* Note that this content type is singular, not plural.
18761878
*/
18771879
if (strcmp(status->content_type.buf,
18781880
"application/x-git-loose-object")) {
@@ -2107,14 +2109,17 @@ static void do_throttle_spin(struct gh__request_params *params,
21072109
strbuf_addstr(&region, gh__server_type_label[params->server_type]);
21082110
trace2_region_enter("gvfs-helper", region.buf, NULL);
21092111

2110-
progress = start_progress(progress_msg, duration);
2112+
if (gh__cmd_opts.show_progress)
2113+
progress = start_progress(progress_msg, duration);
2114+
21112115
while (now < end) {
21122116
display_progress(progress, (now - begin));
21132117

21142118
sleep_millisec(100);
21152119

21162120
now = time(NULL);
21172121
}
2122+
21182123
display_progress(progress, duration);
21192124
stop_progress(&progress);
21202125

@@ -2669,13 +2674,15 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26692674
params.headers = curl_slist_append(params.headers,
26702675
"Content-Type: application/json");
26712676
/*
2672-
* We really always want a packfile. But if the payload only
2673-
* requests 1 OID, the server will send us a single loose
2674-
* objects instead. (Apparently the server ignores us when we
2675-
* only send application/x-git-packfile and does it anyway.)
2677+
* If our POST contains more than one object, we want the
2678+
* server to send us a packfile. We DO NOT want the non-standard
2679+
* concatenated loose object format, so we DO NOT send:
2680+
* "Accept: application/x-git-loose-objects" (plural)
26762681
*
2677-
* So to make it clear to my future self, go ahead and add
2678-
* an accept header for loose objects and own it.
2682+
* However, if the payload only requests 1 OID, the server
2683+
* will send us a single loose object instead of a packfile,
2684+
* so we ACK that and send:
2685+
* "Accept: application/x-git-loose-object" (singular)
26792686
*/
26802687
params.headers = curl_slist_append(params.headers,
26812688
"Accept: application/x-git-packfile");

0 commit comments

Comments
 (0)