Enhance test coverage for transfer cancellation

This commit is contained in:
Ben Straub 2013-02-05 12:10:08 -08:00
parent b71bac9d2b
commit 42385c96d5

View 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);
}