summaryrefslogtreecommitdiff
path: root/tests/odb
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-12-13 11:31:38 -0500
committerEdward Thomson <ethomson@github.com>2017-02-28 13:27:49 +0000
commite6ed0d2f03625f5d6b60db54fc894902d7ddbc32 (patch)
tree6a40c9e2a5873dac410b1294dfca7fdd2790d938 /tests/odb
parent6d3ad7e09ee4b101e8e68f38783e3e4139bc2691 (diff)
downloadlibgit2-e6ed0d2f03625f5d6b60db54fc894902d7ddbc32.tar.gz
odb_loose: fsync tests
Introduce a simple counter that `p_fsync` implements. This is useful for ensuring that `p_fsync` is called when we expect it to be, for example when we have enabled an odb backend to perform `fsync`s when writing objects.
Diffstat (limited to 'tests/odb')
-rw-r--r--tests/odb/loose.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/odb/loose.c b/tests/odb/loose.c
index c91927c4a..43dabcb0c 100644
--- a/tests/odb/loose.c
+++ b/tests/odb/loose.c
@@ -56,11 +56,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_SYNCHRONIZED_OBJECT_CREATION, 0));
cl_fixture_cleanup("test-objects");
}
@@ -150,3 +152,35 @@ 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_SYNCHRONIZED_OBJECT_CREATION, 1));
+ write_object_to_loose_odb(0);
+ cl_assert(p_fsync__cnt > 0);
+}