1
1
#include < gtest/gtest.h> // googletest header file
2
2
#include < am_super/super_node_mediator.h>
3
3
#include < boost/algorithm/string/join.hpp>
4
+ #include < boost/algorithm/string.hpp>
5
+ #include < boost/algorithm/string/join.hpp>
6
+ #include < boost/range/algorithm/copy.hpp>
7
+ #include < boost/range/adaptor/map.hpp>
4
8
5
9
using namespace std ;
6
10
using namespace am ;
@@ -11,8 +15,20 @@ class SuperNodeMediatorTest : public ::testing::Test
11
15
const string SUPER_NODE_NAME = " my_super_node" ;
12
16
SuperNodeMediator superNodeMediator;
13
17
18
+
19
+
14
20
SuperNodeMediatorTest () : superNodeMediator(SUPER_NODE_NAME) {}
15
21
22
+ SuperNodeMediator::SuperNodeInfo manifested_lifecycle_node (string node_name, LifeCycleState state)
23
+ {
24
+ SuperNodeMediator::SuperNodeInfo node;
25
+ node.name = node_name;
26
+ node.online = true ;
27
+ node.manifested = true ;
28
+ node.state = state;
29
+ return node;
30
+ }
31
+
16
32
void ASSERT_CHECK (std::function<bool (SuperNodeMediator::SuperNodeInfo&, SuperNodeMediator&)> check, LifeCycleState state, bool expected,
17
33
OperatorCommand last_op_command_received = OperatorCommand::ARM, ControllerState last_controller_state_received = ControllerState::COMPLETED)
18
34
{
@@ -48,6 +64,20 @@ class SuperNodeMediatorTest : public ::testing::Test
48
64
}
49
65
}
50
66
67
+ void assertAllManifestedNodesCheck (SuperNodeMediator::Supervisor supervisor,
68
+ std::function<bool (SuperNodeMediator::SuperNodeInfo&, SuperNodeMediator&)> check,
69
+ vector<string> expected_failed_nodes, bool expected_success)
70
+ {
71
+ pair<bool , map<string, string>> result = superNodeMediator.allManifestedNodesCheck (supervisor, check);
72
+ vector<string> failed_nodes;
73
+ boost::copy (result.second | boost::adaptors::map_keys, std::back_inserter (failed_nodes));
74
+
75
+ std::sort (failed_nodes.begin (), failed_nodes.end ());
76
+ std::sort (expected_failed_nodes.begin (), expected_failed_nodes.end ());
77
+
78
+ ASSERT_EQ ((failed_nodes == expected_failed_nodes), expected_success);
79
+ }
80
+
51
81
void ASSERT_getStateTransition (const SuperState ¤t_state, const SuperState &expected_state, const OperatorCommand &operator_command = (OperatorCommand)-1,
52
82
const ControllerState& controller_state = (ControllerState)-1)
53
83
{
@@ -204,6 +234,74 @@ TEST_F(SuperNodeMediatorTest, allManifestedNodesCheck_FlightControllerLifeCycleN
204
234
assertAllManifestedNodesCheck (expected_success = true , node, check_result = false , " [WCK2]" );
205
235
}
206
236
237
+ TEST_F (SuperNodeMediatorTest, allManifestedNodesCheck_MultipleNodes_FirstNodeFails)
238
+ {
239
+ SuperNodeMediator::Supervisor supervisor;
240
+ supervisor.system_state = SuperState::BOOTING;
241
+
242
+ // supervisor stores a map<string, SuperNodeInfo>
243
+ supervisor.nodes .insert ({" a" , manifested_lifecycle_node (" a" , LifeCycleState::CONFIGURING)});
244
+ supervisor.nodes .insert ({" b" , manifested_lifecycle_node (" b" , LifeCycleState::INACTIVE)});
245
+ supervisor.nodes .insert ({" c" , manifested_lifecycle_node (" c" , LifeCycleState::INACTIVE)});
246
+ supervisor.nodes .insert ({" d" , manifested_lifecycle_node (" d" , LifeCycleState::INACTIVE)});
247
+
248
+ // a and c should fail
249
+ vector<string> expected_failed_nodes ({" a" });
250
+
251
+ assertAllManifestedNodesCheck (supervisor, SuperNodeMediator::checkReadyToArm, expected_failed_nodes, true );
252
+ }
253
+
254
+ TEST_F (SuperNodeMediatorTest, allManifestedNodesCheck_MultipleNodes_TwoNodesFail)
255
+ {
256
+ SuperNodeMediator::Supervisor supervisor;
257
+ supervisor.system_state = SuperState::BOOTING;
258
+
259
+ // supervisor stores a map<string, SuperNodeInfo>
260
+ supervisor.nodes .insert ({" a" , manifested_lifecycle_node (" a" , LifeCycleState::CONFIGURING)});
261
+ supervisor.nodes .insert ({" b" , manifested_lifecycle_node (" b" , LifeCycleState::CONFIGURING)});
262
+ supervisor.nodes .insert ({" c" , manifested_lifecycle_node (" c" , LifeCycleState::INACTIVE)});
263
+ supervisor.nodes .insert ({" d" , manifested_lifecycle_node (" d" , LifeCycleState::INACTIVE)});
264
+
265
+ // a and b should fail
266
+ vector<string> expected_failed_nodes ({" a" , " b" });
267
+
268
+ assertAllManifestedNodesCheck (supervisor, SuperNodeMediator::checkReadyToArm, expected_failed_nodes, true );
269
+ }
270
+
271
+ TEST_F (SuperNodeMediatorTest, allManifestedNodesCheck_MultipleNodes_AllNodesFail)
272
+ {
273
+ SuperNodeMediator::Supervisor supervisor;
274
+ supervisor.system_state = SuperState::BOOTING;
275
+
276
+ // supervisor stores a map<string, SuperNodeInfo>
277
+ supervisor.nodes .insert ({" a" , manifested_lifecycle_node (" a" , LifeCycleState::CONFIGURING)});
278
+ supervisor.nodes .insert ({" b" , manifested_lifecycle_node (" b" , LifeCycleState::CONFIGURING)});
279
+ supervisor.nodes .insert ({" c" , manifested_lifecycle_node (" c" , LifeCycleState::CONFIGURING)});
280
+ supervisor.nodes .insert ({" d" , manifested_lifecycle_node (" d" , LifeCycleState::CONFIGURING)});
281
+
282
+ // all should fail
283
+ vector<string> expected_failed_nodes ({" a" , " b" , " c" , " d" });
284
+
285
+ assertAllManifestedNodesCheck (supervisor, SuperNodeMediator::checkReadyToArm, expected_failed_nodes, true );
286
+ }
287
+
288
+ TEST_F (SuperNodeMediatorTest, allManifestedNodesCheck_MultipleNodes_AllNodesPass)
289
+ {
290
+ SuperNodeMediator::Supervisor supervisor;
291
+ supervisor.system_state = SuperState::BOOTING;
292
+
293
+ // supervisor stores a map<string, SuperNodeInfo>
294
+ supervisor.nodes .insert ({" a" , manifested_lifecycle_node (" a" , LifeCycleState::INACTIVE)});
295
+ supervisor.nodes .insert ({" b" , manifested_lifecycle_node (" b" , LifeCycleState::INACTIVE)});
296
+ supervisor.nodes .insert ({" c" , manifested_lifecycle_node (" c" , LifeCycleState::INACTIVE)});
297
+ supervisor.nodes .insert ({" d" , manifested_lifecycle_node (" d" , LifeCycleState::INACTIVE)});
298
+
299
+ // none should fail
300
+ vector<string> expected_failed_nodes ({});
301
+
302
+ assertAllManifestedNodesCheck (supervisor, SuperNodeMediator::checkReadyToArm, expected_failed_nodes, true );
303
+ }
304
+
207
305
TEST_F (SuperNodeMediatorTest, parseManifest_EmptyManifest)
208
306
{
209
307
SuperNodeMediator::Supervisor supervisor;
0 commit comments