]> git.proxmox.com Git - libgit2.git/commitdiff
Enhance test coverage for transfer cancellation
authorBen Straub <bs@github.com>
Tue, 5 Feb 2013 20:10:08 +0000 (12:10 -0800)
committerBen Straub <bs@github.com>
Tue, 5 Feb 2013 20:10:08 +0000 (12:10 -0800)
tests-clar/online/fetch.c

index d0753277828589ab402d872c571cdc8651400555..a0ee7aac815ad3ae1c259dcacf0ba1e467984bd5 100644 (file)
@@ -112,3 +112,25 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
        git_remote_free(remote);
        git_repository_free(_repository);
 }
+
+static int cancel_at_half(const git_transfer_progress *stats, void *payload)
+{
+       GIT_UNUSED(payload);
+
+       if (stats->received_objects > (stats->total_objects/2))
+               return -1;
+       return 0;
+}
+
+void test_online_fetch__can_cancel(void)
+{
+       git_remote *remote;
+       size_t bytes_received = 0;
+
+       cl_git_pass(git_remote_create(&remote, _repo, "test",
+                               "http://github.com/libgit2/TestGitRepository.git"));
+       cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+       cl_git_fail_with(git_remote_download(remote, cancel_at_half, &bytes_received), GIT_EUSER);
+       git_remote_disconnect(remote);
+       git_remote_free(remote);
+}