summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-02-12 10:13:56 -0800
committerRussell Belfer <rb@github.com>2013-02-12 10:13:56 -0800
commit9c258af094aec53b8e4bcaabe1e2f054ba385982 (patch)
tree384be2f6ea9c70b02f60ab48cfa492a846d496f3 /tests-clar
parent40a605104c2060c2bc5a08dfb62cafe473baeb21 (diff)
parentea57f66b5786704448152ebd95139802826bef1d (diff)
downloadlibgit2-9c258af094aec53b8e4bcaabe1e2f054ba385982.tar.gz
Merge pull request #1316 from ben/clone-cancel
Allow network operations to cancel
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/network/fetchlocal.c3
-rw-r--r--tests-clar/online/clone.c18
-rw-r--r--tests-clar/online/fetch.c28
3 files changed, 45 insertions, 4 deletions
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
index ee3bd9db3..e2ba675e1 100644
--- a/tests-clar/network/fetchlocal.c
+++ b/tests-clar/network/fetchlocal.c
@@ -4,11 +4,12 @@
#include "path.h"
#include "remote.h"
-static void transfer_cb(const git_transfer_progress *stats, void *payload)
+static int transfer_cb(const git_transfer_progress *stats, void *payload)
{
int *callcount = (int*)payload;
GIT_UNUSED(stats);
(*callcount)++;
+ return 0;
}
static void cleanup_local_repo(void *path)
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
index 6a46fa511..c1a9a9a88 100644
--- a/tests-clar/online/clone.c
+++ b/tests-clar/online/clone.c
@@ -81,11 +81,12 @@ static void checkout_progress(const char *path, size_t cur, size_t tot, void *pa
(*was_called) = true;
}
-static void fetch_progress(const git_transfer_progress *stats, void *payload)
+static int fetch_progress(const git_transfer_progress *stats, void *payload)
{
bool *was_called = (bool*)payload;
GIT_UNUSED(stats);
(*was_called) = true;
+ return 0;
}
void test_online_clone__can_checkout_a_cloned_repo(void)
@@ -182,3 +183,18 @@ void test_online_clone__bitbucket_style(void)
git_repository_free(g_repo); g_repo = NULL;
cl_fixture_cleanup("./foo");
}
+
+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_clone__can_cancel(void)
+{
+ g_options.fetch_progress_cb = cancel_at_half;
+ cl_git_fail_with(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), GIT_EUSER);
+}
diff --git a/tests-clar/online/fetch.c b/tests-clar/online/fetch.c
index 41cdb30e1..a0ee7aac8 100644
--- a/tests-clar/online/fetch.c
+++ b/tests-clar/online/fetch.c
@@ -25,10 +25,11 @@ static int update_tips(const char *refname, const git_oid *a, const git_oid *b,
return 0;
}
-static void progress(const git_transfer_progress *stats, void *payload)
+static int progress(const git_transfer_progress *stats, void *payload)
{
size_t *bytes_received = (size_t *)payload;
*bytes_received = stats->received_bytes;
+ return 0;
}
static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
@@ -73,12 +74,13 @@ void test_online_fetch__no_tags_http(void)
do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
}
-static void transferProgressCallback(const git_transfer_progress *stats, void *payload)
+static int transferProgressCallback(const git_transfer_progress *stats, void *payload)
{
bool *invoked = (bool *)payload;
GIT_UNUSED(stats);
*invoked = true;
+ return 0;
}
void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date(void)
@@ -110,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);
+}