summaryrefslogtreecommitdiff
path: root/tests/odb
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-03-22 20:29:22 +0000
committerGitHub <noreply@github.com>2017-03-22 20:29:22 +0000
commit6fd6c67824d2caad9f8716a676820d8319f79a9d (patch)
tree00393d0a78fe42c3c007ca71e8da50374781d437 /tests/odb
parent7e53e8ce454b31e933b7ad6df90ffdfdc678cd81 (diff)
parent1c04a96b25da048221f31ecee0227d960dc00489 (diff)
downloadlibgit2-6fd6c67824d2caad9f8716a676820d8319f79a9d.tar.gz
Merge pull request #4030 from libgit2/ethomson/fsync
fsync all the things
Diffstat (limited to 'tests/odb')
-rw-r--r--tests/odb/loose.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/odb/loose.c b/tests/odb/loose.c
index c91927c4a..dd686aa01 100644
--- a/tests/odb/loose.c
+++ b/tests/odb/loose.c
@@ -3,6 +3,7 @@
#include "git2/odb_backend.h"
#include "posix.h"
#include "loose_data.h"
+#include "repository.h"
#ifdef __ANDROID_API__
# define S_IREAD S_IRUSR
@@ -56,11 +57,13 @@ static void test_read_object(object_data *data)
void test_odb_loose__initialize(void)
{
+ p_fsync__cnt = 0;
cl_must_pass(p_mkdir("test-objects", GIT_OBJECT_DIR_MODE));
}
void test_odb_loose__cleanup(void)
{
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION, 0));
cl_fixture_cleanup("test-objects");
}
@@ -150,3 +153,55 @@ void test_odb_loose__permissions_readwrite(void)
{
test_write_object_permission(0777, 0666, 0777, 0666);
}
+
+static void write_object_to_loose_odb(int fsync)
+{
+ git_odb *odb;
+ git_odb_backend *backend;
+ git_oid oid;
+
+ cl_git_pass(git_odb_new(&odb));
+ cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, fsync, 0777, 0666));
+ cl_git_pass(git_odb_add_backend(odb, backend, 1));
+ cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJ_BLOB));
+ git_odb_free(odb);
+}
+
+void test_odb_loose__does_not_fsync_by_default(void)
+{
+ write_object_to_loose_odb(0);
+ cl_assert_equal_sz(0, p_fsync__cnt);
+}
+
+void test_odb_loose__fsync_obeys_odb_option(void)
+{
+ write_object_to_loose_odb(1);
+ cl_assert(p_fsync__cnt > 0);
+}
+
+void test_odb_loose__fsync_obeys_global_setting(void)
+{
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION, 1));
+ write_object_to_loose_odb(0);
+ cl_assert(p_fsync__cnt > 0);
+}
+
+void test_odb_loose__fsync_obeys_repo_setting(void)
+{
+ git_repository *repo;
+ git_odb *odb;
+ git_oid oid;
+
+ cl_git_pass(git_repository_init(&repo, "test-objects", 1));
+ cl_git_pass(git_repository_odb__weakptr(&odb, repo));
+ cl_git_pass(git_odb_write(&oid, odb, "No fsync here\n", 14, GIT_OBJ_BLOB));
+ cl_assert(p_fsync__cnt == 0);
+ git_repository_free(repo);
+
+ cl_git_pass(git_repository_open(&repo, "test-objects"));
+ cl_repo_set_bool(repo, "core.fsyncObjectFiles", true);
+ cl_git_pass(git_repository_odb__weakptr(&odb, repo));
+ cl_git_pass(git_odb_write(&oid, odb, "Now fsync\n", 10, GIT_OBJ_BLOB));
+ cl_assert(p_fsync__cnt > 0);
+ git_repository_free(repo);
+}