diff options
| author | Patrick Steinhardt <ps@pks.im> | 2016-11-04 18:18:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-04 18:18:46 +0100 |
| commit | 5fe5557e8a8d3fd6a4617c2d8c863c1f62848020 (patch) | |
| tree | 33d5f25050b1f60ab88ac5165ced639a45a1e76b /tests | |
| parent | 6e2fab9eded4c815d52ff812671fd7a601ef19d6 (diff) | |
| parent | 1c33ecc4456186f4cc6570876ed5c47031b7ef1b (diff) | |
| download | libgit2-5fe5557e8a8d3fd6a4617c2d8c863c1f62848020.tar.gz | |
Merge pull request #3974 from libgit2/pks/synchronize-shutdown
global: synchronize initialization and shutdown with pthreads
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/init.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/core/init.c b/tests/core/init.c index e17b7845f..cd90b378d 100644 --- a/tests/core/init.c +++ b/tests/core/init.c @@ -12,3 +12,43 @@ void test_core_init__returns_count(void) cl_assert_equal_i(1, git_libgit2_shutdown()); } +void test_core_init__reinit_succeeds(void) +{ + cl_assert_equal_i(0, git_libgit2_shutdown()); + cl_assert_equal_i(1, git_libgit2_init()); + cl_sandbox_set_search_path_defaults(); +} + +#ifdef GIT_THREADS +static void *reinit(void *unused) +{ + unsigned i; + + for (i = 0; i < 20; i++) { + cl_assert(git_libgit2_init() > 0); + cl_assert(git_libgit2_shutdown() >= 0); + } + + return unused; +} +#endif + +void test_core_init__concurrent_init_succeeds(void) +{ +#ifdef GIT_THREADS + git_thread threads[10]; + unsigned i; + + cl_assert_equal_i(0, git_libgit2_shutdown()); + + for (i = 0; i < ARRAY_SIZE(threads); i++) + git_thread_create(&threads[i], reinit, NULL); + for (i = 0; i < ARRAY_SIZE(threads); i++) + git_thread_join(&threads[i], NULL); + + cl_assert_equal_i(1, git_libgit2_init()); + cl_sandbox_set_search_path_defaults(); +#else + cl_skip(); +#endif +} |
