Skip to content

Commit 1c33ecc

Browse files
committed
tests: core: test deinitialization and concurrent initialization
Exercise the logic surrounding deinitialization of the libgit2 library as well as repeated concurrent de- and reinitialization. This tries to catch races and makes sure that it is possible to reinitialize libgit2 multiple times. After deinitializing libgit2, we have to make sure to setup options required for testing. Currently, this only includes setting up the configuration search path again. Before, this has been set up once in `tests/main.c`.
1 parent 038f0e1 commit 1c33ecc

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/core/init.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,43 @@ void test_core_init__returns_count(void)
1212
cl_assert_equal_i(1, git_libgit2_shutdown());
1313
}
1414

15+
void test_core_init__reinit_succeeds(void)
16+
{
17+
cl_assert_equal_i(0, git_libgit2_shutdown());
18+
cl_assert_equal_i(1, git_libgit2_init());
19+
cl_sandbox_set_search_path_defaults();
20+
}
21+
22+
#ifdef GIT_THREADS
23+
static void *reinit(void *unused)
24+
{
25+
unsigned i;
26+
27+
for (i = 0; i < 20; i++) {
28+
cl_assert(git_libgit2_init() > 0);
29+
cl_assert(git_libgit2_shutdown() >= 0);
30+
}
31+
32+
return unused;
33+
}
34+
#endif
35+
36+
void test_core_init__concurrent_init_succeeds(void)
37+
{
38+
#ifdef GIT_THREADS
39+
git_thread threads[10];
40+
unsigned i;
41+
42+
cl_assert_equal_i(0, git_libgit2_shutdown());
43+
44+
for (i = 0; i < ARRAY_SIZE(threads); i++)
45+
git_thread_create(&threads[i], reinit, NULL);
46+
for (i = 0; i < ARRAY_SIZE(threads); i++)
47+
git_thread_join(&threads[i], NULL);
48+
49+
cl_assert_equal_i(1, git_libgit2_init());
50+
cl_sandbox_set_search_path_defaults();
51+
#else
52+
cl_skip();
53+
#endif
54+
}

0 commit comments

Comments
 (0)