rosbag_recorder.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #include <gmock/gmock.h>
16 #include <gtest/gtest.h>
17 
18 #include <chrono>
19 #include <condition_variable>
20 #include <future>
21 #include <mutex>
22 #include <thread>
23 
25 
26 using namespace Aws::Rosbag::Utils;
27 
29 {
30 public:
31  MockRecorder(RecorderOptions const& options) {
32  (void) options;
33  };
35 
36  int Run()
37  {
38  using namespace std::chrono_literals;
39  std::this_thread::sleep_for(100ms);
40  return 0;
41  }
42 };
43 
44 TEST(TestRosbagRecorder, TestRosbagRecorderRun)
45 {
47  RosbagRecorder<MockRecorder> rosbag_recorder;
48 
49  ASSERT_FALSE(rosbag_recorder.IsActive());
50 
51  std::promise<bool> pre_invoked;
52  std::promise<bool> post_invoked;
53 
54  std::future<bool> pre_invoked_f = pre_invoked.get_future();
55  std::future<bool> post_invoked_f = post_invoked.get_future();
56  auto result = rosbag_recorder.Run(
57  options,
58  [&]
59  {
60  pre_invoked.set_value(true);
61  },
62  [&](int exit_code)
63  {
64  ASSERT_EQ(exit_code, 0);
65  post_invoked.set_value(true);
66  }
67  );
68  ASSERT_EQ(result, RosbagRecorderRunResult::STARTED);
69  ASSERT_TRUE(pre_invoked_f.get());
70  ASSERT_TRUE(post_invoked_f.get());
71 }
72 
73 TEST(TestRosbagRecorder, TestRosbagRecorderIsActive)
74 {
75  RosbagRecorder<MockRecorder> rosbag_recorder;
77 
78  std::promise<void> barrier;
79  std::future<void> barrier_future = barrier.get_future();
80 
81  ASSERT_FALSE(rosbag_recorder.IsActive());
82 
83  auto result = rosbag_recorder.Run(
84  options,
85  []
86  {
87  },
88  [&](int exit_code)
89  {
90  ASSERT_EQ(exit_code, 0);
91  barrier_future.wait();
92  }
93  );
94 
95  ASSERT_EQ(result, RosbagRecorderRunResult::STARTED);
96  ASSERT_TRUE(rosbag_recorder.IsActive());
97 
98  result = rosbag_recorder.Run(
99  options,
100  []
101  {
102  },
103  [&](int exit_code)
104  {
105  (void) exit_code;
106  }
107  );
108 
109  ASSERT_EQ(result, RosbagRecorderRunResult::SKIPPED);
110 
111  barrier.set_value();
112 
113  using namespace std::chrono_literals;
114  std::this_thread::sleep_for(1s);
115 
116  ASSERT_FALSE(rosbag_recorder.IsActive());
117 }
virtual RosbagRecorderRunResult Run(const RecorderOptions &recorder_options, const std::function< void()> &pre_record=nullptr, const std::function< void(int)> &post_record=nullptr)
TEST(TestRosbagRecorder, TestRosbagRecorderRun)
XmlRpcServer s
options
MockRecorder(RecorderOptions const &options)


rosbag_cloud_recorders
Author(s): AWS RoboMaker
autogenerated on Tue Jun 1 2021 02:51:27