Skip to content

Commit

Permalink
test-gvfs-prococol, t5799: tests for gvfs-helper
Browse files Browse the repository at this point in the history
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 <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johasc@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Sep 18, 2024
1 parent c19200a commit cd7b1b8
Show file tree
Hide file tree
Showing 5 changed files with 2,763 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ endif
BASIC_CFLAGS += $(CURL_CFLAGS)

PROGRAM_OBJS += gvfs-helper.o
TEST_PROGRAMS_NEED_X += test-gvfs-protocol

REMOTE_CURL_PRIMARY = git-remote-http$X
REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
Expand Down
14 changes: 14 additions & 0 deletions contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,20 @@ set(wrapper_scripts
set(wrapper_test_scripts
test-fake-ssh test-tool)

if(CURL_FOUND)
list(APPEND wrapper_test_scripts test-gvfs-protocol)

add_executable(test-gvfs-protocol ${CMAKE_SOURCE_DIR}/t/helper/test-gvfs-protocol.c)
target_link_libraries(test-gvfs-protocol common-main)

if(MSVC)
set_target_properties(test-gvfs-protocol
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper)
set_target_properties(test-gvfs-protocol
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper)
endif()
endif()


foreach(script ${wrapper_scripts})
file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
Expand Down
21 changes: 14 additions & 7 deletions gvfs-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,8 @@ static void install_loose(struct gh__request_params *params,
/*
* We expect a loose object when we do a GET -or- when we
* do a POST with only 1 object.
*
* Note that this content type is singular, not plural.
*/
if (strcmp(status->content_type.buf,
"application/x-git-loose-object")) {
Expand Down Expand Up @@ -2117,14 +2119,17 @@ static void do_throttle_spin(struct gh__request_params *params,
strbuf_addstr(&region, gh__server_type_label[params->server_type]);
trace2_region_enter("gvfs-helper", region.buf, NULL);

progress = start_progress(progress_msg, duration);
if (gh__cmd_opts.show_progress)
progress = start_progress(progress_msg, duration);

while (now < end) {
display_progress(progress, (now - begin));

sleep_millisec(100);

now = time(NULL);
}

display_progress(progress, duration);
stop_progress(&progress);

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

0 comments on commit cd7b1b8

Please sign in to comment.