process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
cross_process_sync_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
20 
22 
23 #include <gtest/gtest.h>
24 
25 TEST(CrossProcessSync, signalling_the_sync_object_results_in_correct_count)
26 {
28 
29  auto service = [&cps]()
30  {
31  for (unsigned int i = 1; i <= 50; i++)
32  {
33  EXPECT_NO_THROW(cps.try_signal_ready_for(std::chrono::milliseconds{500}));
34  }
35  return ::testing::Test::HasFailure() ?
37  };
38 
39  auto client = [&cps]()
40  {
41  std::uint32_t counter = 0;
42  for (unsigned int i = 1; i <= 50; i++)
43  {
44  EXPECT_NO_THROW(counter = cps.wait_for_signal_ready_for(std::chrono::milliseconds{500}));
45  EXPECT_EQ(i, counter);
46  }
47 
48  return ::testing::Test::HasFailure() ?
50  };
51 
53 }
54 
55 TEST(CrossProcessSync, timed_out_wait_on_sync_object_throws_correct_exception)
56 {
58 
59  EXPECT_THROW(cps.wait_for_signal_ready_for(std::chrono::milliseconds{1}),
61 }
TEST(CrossProcessSync, signalling_the_sync_object_results_in_correct_count)
CORE_POSIX_DLL_PUBLIC ForkAndRunResult fork_and_run(const std::function< core::posix::exit::Status()> &service, const std::function< core::posix::exit::Status()> &client)
Forks two processes for both the service and the client.
A cross-process synchronization primitive that supports simple wait-condition-like scenarios...
Special value indicating no bit being set.
void try_signal_ready_for(const std::chrono::milliseconds &duration)
Try to signal the other side that we are ready for at most duration milliseconds. ...
std::uint32_t wait_for_signal_ready_for(const std::chrono::milliseconds &duration)
Wait for the other sides to signal readiness for at most duration milliseconds.
Thrown if any of the *_for functions times out.