blob: b8fc5b6a76ef27b4a34a8da9deff35a63329dfca [file] [log] [blame]
Austin Schuhcb108412019-10-13 16:09:54 -07001#include "aos/configuration.h"
2
3#include "absl/strings/strip.h"
4#include "aos/json_to_flatbuffer.h"
5#include "aos/testing/test_logging.h"
6#include "aos/util/file.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07007#include "flatbuffers/reflection.h"
8#include "glog/logging.h"
Austin Schuhcb108412019-10-13 16:09:54 -07009#include "gtest/gtest.h"
Austin Schuhe84c3ed2019-12-14 15:29:48 -080010#include "gmock/gmock.h"
Austin Schuhcb108412019-10-13 16:09:54 -070011
12namespace aos {
13namespace configuration {
14namespace testing {
15
16class ConfigurationTest : public ::testing::Test {
17 public:
18 ConfigurationTest() { ::aos::testing::EnableTestLogging(); }
19};
20
21typedef ConfigurationTest ConfigurationDeathTest;
22
23// *the* expected location for all working tests.
24const char *kExpectedLocation =
25 "{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"max_size\": 5 }";
Austin Schuhbca6cf02019-12-22 17:28:34 -080026// And for multinode setups
27const char *kExpectedMultinodeLocation =
28 "{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"max_size\": 5, \"source_node\": \"pi1\" }";
Austin Schuhcb108412019-10-13 16:09:54 -070029
30// Tests that we can read and merge a configuration.
31TEST_F(ConfigurationTest, ConfigMerge) {
Austin Schuh40485ed2019-10-26 21:51:44 -070032 FlatbufferDetachedBuffer<Configuration> config =
33 ReadConfig("aos/testdata/config1.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -070034 LOG(INFO) << "Read: " << FlatbufferToJson(config, true);
Austin Schuhcb108412019-10-13 16:09:54 -070035
36 EXPECT_EQ(
37 absl::StripSuffix(
38 util::ReadFileToStringOrDie("aos/testdata/expected.json"), "\n"),
39 FlatbufferToJson(config, true));
40}
41
Austin Schuh217a9782019-12-21 23:02:50 -080042// Tests that we can read and merge a multinode configuration.
43TEST_F(ConfigurationTest, ConfigMergeMultinode) {
44 FlatbufferDetachedBuffer<Configuration> config =
45 ReadConfig("aos/testdata/config1_multinode.json");
46 LOG(INFO) << "Read: " << FlatbufferToJson(config, true);
47
48 EXPECT_EQ(
49 std::string(absl::StripSuffix(
50 util::ReadFileToStringOrDie("aos/testdata/expected_multinode.json"),
51 "\n")),
52 FlatbufferToJson(config, true));
53}
54
Alex Perrycb7da4b2019-08-28 19:35:56 -070055// Tests that we sort the entries in a config so we can look entries up.
56TEST_F(ConfigurationTest, UnsortedConfig) {
57 FlatbufferDetachedBuffer<Configuration> config =
58 ReadConfig("aos/testdata/backwards.json");
59
60 LOG(INFO) << "Read: " << FlatbufferToJson(config, true);
61
62 EXPECT_EQ(FlatbufferToJson(GetChannel(config, ".aos.robot_state",
Austin Schuhbca6cf02019-12-22 17:28:34 -080063 "aos.RobotState", "app1", nullptr)),
Alex Perrycb7da4b2019-08-28 19:35:56 -070064 "{ \"name\": \".aos.robot_state\", \"type\": \"aos.RobotState\", "
65 "\"max_size\": 5 }");
66}
67
Austin Schuhcb108412019-10-13 16:09:54 -070068// Tests that we die when a file is imported twice.
69TEST_F(ConfigurationDeathTest, DuplicateFile) {
70 EXPECT_DEATH(
71 {
Austin Schuh40485ed2019-10-26 21:51:44 -070072 FlatbufferDetachedBuffer<Configuration> config =
Austin Schuhcb108412019-10-13 16:09:54 -070073 ReadConfig("aos/testdata/config1_bad.json");
74 },
75 "aos/testdata/config1_bad.json");
76}
77
78// Tests that we can lookup a location, complete with maps, from a merged
79// config.
Austin Schuh40485ed2019-10-26 21:51:44 -070080TEST_F(ConfigurationTest, GetChannel) {
81 FlatbufferDetachedBuffer<Configuration> config =
82 ReadConfig("aos/testdata/config1.json");
Austin Schuhcb108412019-10-13 16:09:54 -070083
84 // Test a basic lookup first.
Austin Schuhbca6cf02019-12-22 17:28:34 -080085 EXPECT_EQ(
86 FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app1", nullptr)),
87 kExpectedLocation);
Austin Schuhcb108412019-10-13 16:09:54 -070088
89 // Test that an invalid name results in nullptr back.
Austin Schuhbca6cf02019-12-22 17:28:34 -080090 EXPECT_EQ(GetChannel(config, "/invalid_name", ".aos.bar", "app1", nullptr),
91 nullptr);
Austin Schuhcb108412019-10-13 16:09:54 -070092
93 // Tests that a root map/rename works. And that they get processed from the
94 // bottom up.
Austin Schuhbca6cf02019-12-22 17:28:34 -080095 EXPECT_EQ(FlatbufferToJson(
96 GetChannel(config, "/batman", ".aos.bar", "app1", nullptr)),
97 kExpectedLocation);
Austin Schuhcb108412019-10-13 16:09:54 -070098
99 // And then test that an application specific map/rename works.
Austin Schuhbca6cf02019-12-22 17:28:34 -0800100 EXPECT_EQ(
101 FlatbufferToJson(GetChannel(config, "/bar", ".aos.bar", "app1", nullptr)),
102 kExpectedLocation);
103 EXPECT_EQ(
104 FlatbufferToJson(GetChannel(config, "/baz", ".aos.bar", "app2", nullptr)),
105 kExpectedLocation);
Austin Schuhcb108412019-10-13 16:09:54 -0700106
107 // And then test that an invalid application name gets properly ignored.
Austin Schuhbca6cf02019-12-22 17:28:34 -0800108 EXPECT_EQ(
109 FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app3", nullptr)),
110 kExpectedLocation);
111}
112
113// Tests that we can lookup a location with node specific maps.
114TEST_F(ConfigurationTest, GetChannelMultinode) {
115 FlatbufferDetachedBuffer<Configuration> config =
116 ReadConfig("aos/testdata/good_multinode.json");
117 const Node *pi1 = GetNode(&config.message(), "pi1");
118 const Node *pi2 = GetNode(&config.message(), "pi2");
119
120 // Test a basic lookup first.
121 EXPECT_EQ(
122 FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app1", pi1)),
123 kExpectedMultinodeLocation);
124 EXPECT_EQ(
125 FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app1", pi2)),
126 kExpectedMultinodeLocation);
127
128 // Tests that a root map/rename works with a node specific map.
129 EXPECT_EQ(FlatbufferToJson(
130 GetChannel(config, "/batman", ".aos.bar", "app1", pi1)),
131 kExpectedMultinodeLocation);
132
133 // Tests that a root map/rename fails with a node specific map for the wrong
134 // node.
135 EXPECT_EQ(GetChannel(config, "/batman", ".aos.bar", "app1", pi2), nullptr);
136
137 // And then test that an application specific map/rename works.
138 EXPECT_EQ(
139 FlatbufferToJson(GetChannel(config, "/batman2", ".aos.bar", "app1", pi1)),
140 kExpectedMultinodeLocation);
141 EXPECT_EQ(
142 FlatbufferToJson(GetChannel(config, "/batman3", ".aos.bar", "app1", pi1)),
143 kExpectedMultinodeLocation);
144
145 // And then that it fails when the node changes.
146 EXPECT_EQ(GetChannel(config, "/batman3", ".aos.bar", "app1", pi2), nullptr);
147}
148
149// Tests that we can lookup a location with type specific maps.
150TEST_F(ConfigurationTest, GetChannelTypedMultinode) {
151 FlatbufferDetachedBuffer<Configuration> config =
152 ReadConfig("aos/testdata/good_multinode.json");
153 const Node *pi1 = GetNode(&config.message(), "pi1");
154
155 // Test a basic lookup first.
156 EXPECT_EQ(
157 FlatbufferToJson(GetChannel(config, "/batman", ".aos.bar", "app1", pi1)),
158 kExpectedMultinodeLocation);
159
160 // Now confirm that a second message on the same name doesn't get remapped.
161 const char *kExpectedBazMultinodeLocation =
162 "{ \"name\": \"/batman\", \"type\": \".aos.baz\", \"max_size\": 5, "
163 "\"source_node\": \"pi1\" }";
164 EXPECT_EQ(
165 FlatbufferToJson(GetChannel(config, "/batman", ".aos.baz", "app1", pi1)),
166 kExpectedBazMultinodeLocation);
Austin Schuhcb108412019-10-13 16:09:54 -0700167}
168
Austin Schuh217a9782019-12-21 23:02:50 -0800169// Tests that we reject a configuration which has a nodes list, but has channels
170// withoout source_node filled out.
171TEST_F(ConfigurationDeathTest, InvalidSourceNode) {
172 EXPECT_DEATH(
173 {
174 FlatbufferDetachedBuffer<Configuration> config =
175 ReadConfig("aos/testdata/invalid_nodes.json");
176 },
177 "source_node");
178
179 EXPECT_DEATH(
180 {
181 FlatbufferDetachedBuffer<Configuration> config =
182 ReadConfig("aos/testdata/invalid_source_node.json");
183 },
184 "source_node");
185
186 EXPECT_DEATH(
187 {
188 FlatbufferDetachedBuffer<Configuration> config =
189 ReadConfig("aos/testdata/invalid_destination_node.json");
190 },
191 "destination_nodes");
192
193 EXPECT_DEATH(
194 {
195 FlatbufferDetachedBuffer<Configuration> config =
196 ReadConfig("aos/testdata/self_forward.json");
197 },
198 "forwarding data to itself");
199}
200
201// Tests that our node writeable helpers work as intended.
202TEST_F(ConfigurationTest, ChannelIsSendableOnNode) {
203 FlatbufferDetachedBuffer<Channel> good_channel(JsonToFlatbuffer(
Austin Schuh719946b2019-12-28 14:51:01 -0800204 R"channel({
Austin Schuh217a9782019-12-21 23:02:50 -0800205 "name": "/test",
206 "type": "aos.examples.Ping",
207 "source_node": "foo"
208})channel",
209 Channel::MiniReflectTypeTable()));
210
211 FlatbufferDetachedBuffer<Channel> bad_channel(JsonToFlatbuffer(
Austin Schuh719946b2019-12-28 14:51:01 -0800212 R"channel({
Austin Schuh217a9782019-12-21 23:02:50 -0800213 "name": "/test",
214 "type": "aos.examples.Ping",
215 "source_node": "bar"
216})channel",
217 Channel::MiniReflectTypeTable()));
218
219 FlatbufferDetachedBuffer<Node> node(JsonToFlatbuffer(
Austin Schuh719946b2019-12-28 14:51:01 -0800220 R"node({
Austin Schuh217a9782019-12-21 23:02:50 -0800221 "name": "foo"
222})node",
223 Node::MiniReflectTypeTable()));
224
225 EXPECT_TRUE(
226 ChannelIsSendableOnNode(&good_channel.message(), &node.message()));
227 EXPECT_FALSE(
228 ChannelIsSendableOnNode(&bad_channel.message(), &node.message()));
229}
230
231// Tests that our node readable and writeable helpers work as intended.
232TEST_F(ConfigurationTest, ChannelIsReadableOnNode) {
233 FlatbufferDetachedBuffer<Channel> good_channel(JsonToFlatbuffer(
Austin Schuh719946b2019-12-28 14:51:01 -0800234 R"channel({
Austin Schuh217a9782019-12-21 23:02:50 -0800235 "name": "/test",
236 "type": "aos.examples.Ping",
237 "source_node": "bar",
238 "destination_nodes": [
Austin Schuh719946b2019-12-28 14:51:01 -0800239 {
240 "name": "baz"
241 },
242 {
243 "name": "foo"
244 }
Austin Schuh217a9782019-12-21 23:02:50 -0800245 ]
246})channel",
247 Channel::MiniReflectTypeTable()));
248
249 FlatbufferDetachedBuffer<Channel> bad_channel1(JsonToFlatbuffer(
Austin Schuh719946b2019-12-28 14:51:01 -0800250 R"channel({
Austin Schuh217a9782019-12-21 23:02:50 -0800251 "name": "/test",
252 "type": "aos.examples.Ping",
253 "source_node": "bar"
254})channel",
255 Channel::MiniReflectTypeTable()));
256
257 FlatbufferDetachedBuffer<Channel> bad_channel2(JsonToFlatbuffer(
Austin Schuh719946b2019-12-28 14:51:01 -0800258 R"channel({
Austin Schuh217a9782019-12-21 23:02:50 -0800259 "name": "/test",
260 "type": "aos.examples.Ping",
261 "source_node": "bar",
262 "destination_nodes": [
Austin Schuh719946b2019-12-28 14:51:01 -0800263 {
264 "name": "baz"
265 }
Austin Schuh217a9782019-12-21 23:02:50 -0800266 ]
267})channel",
268 Channel::MiniReflectTypeTable()));
269
270 FlatbufferDetachedBuffer<Node> node(JsonToFlatbuffer(
Austin Schuh719946b2019-12-28 14:51:01 -0800271 R"node({
Austin Schuh217a9782019-12-21 23:02:50 -0800272 "name": "foo"
273})node",
274 Node::MiniReflectTypeTable()));
275
276 EXPECT_TRUE(
277 ChannelIsReadableOnNode(&good_channel.message(), &node.message()));
278 EXPECT_FALSE(
279 ChannelIsReadableOnNode(&bad_channel1.message(), &node.message()));
280 EXPECT_FALSE(
281 ChannelIsReadableOnNode(&bad_channel2.message(), &node.message()));
282}
283
Austin Schuh719946b2019-12-28 14:51:01 -0800284// Tests that our node message is logged helpers work as intended.
285TEST_F(ConfigurationTest, ChannelMessageIsLoggedOnNode) {
286 FlatbufferDetachedBuffer<Channel> logged_on_self_channel(JsonToFlatbuffer(
287 R"channel({
288 "name": "/test",
289 "type": "aos.examples.Ping",
290 "source_node": "bar",
291 "destination_nodes": [
292 {
293 "name": "baz"
294 }
295 ]
296})channel",
297 Channel::MiniReflectTypeTable()));
Austin Schuh217a9782019-12-21 23:02:50 -0800298
Austin Schuh719946b2019-12-28 14:51:01 -0800299 FlatbufferDetachedBuffer<Channel> not_logged_channel(JsonToFlatbuffer(
300 R"channel({
301 "name": "/test",
302 "type": "aos.examples.Ping",
303 "source_node": "bar",
304 "logger": "NOT_LOGGED",
305 "destination_nodes": [
306 {
307 "name": "baz",
308 "timestamp_logger": "LOCAL_LOGGER"
309 }
310 ]
311})channel",
312 Channel::MiniReflectTypeTable()));
313
314 FlatbufferDetachedBuffer<Channel> logged_on_remote_channel(JsonToFlatbuffer(
315 R"channel({
316 "name": "/test",
317 "type": "aos.examples.Ping",
318 "source_node": "bar",
319 "logger": "REMOTE_LOGGER",
320 "logger_node": "baz",
321 "destination_nodes": [
322 {
323 "name": "baz"
324 }
325 ]
326})channel",
327 Channel::MiniReflectTypeTable()));
328
329 FlatbufferDetachedBuffer<Channel> logged_on_separate_logger_node_channel(
330 JsonToFlatbuffer(
331 R"channel({
332 "name": "/test",
333 "type": "aos.examples.Ping",
334 "source_node": "bar",
335 "logger": "REMOTE_LOGGER",
336 "logger_node": "foo",
337 "destination_nodes": [
338 {
339 "name": "baz"
340 }
341 ]
342})channel",
343 Channel::MiniReflectTypeTable()));
344
345 FlatbufferDetachedBuffer<Channel> logged_on_both_channel (
346 JsonToFlatbuffer(
347 R"channel({
348 "name": "/test",
349 "type": "aos.examples.Ping",
350 "source_node": "bar",
351 "logger": "LOCAL_AND_REMOTE_LOGGER",
352 "logger_node": "baz",
353 "destination_nodes": [
354 {
355 "name": "baz"
356 }
357 ]
358})channel",
359 Channel::MiniReflectTypeTable()));
360
361 FlatbufferDetachedBuffer<Node> foo_node(JsonToFlatbuffer(
362 R"node({
363 "name": "foo"
364})node",
365 Node::MiniReflectTypeTable()));
366
367 FlatbufferDetachedBuffer<Node> bar_node(JsonToFlatbuffer(
368 R"node({
369 "name": "bar"
370})node",
371 Node::MiniReflectTypeTable()));
372
373 FlatbufferDetachedBuffer<Node> baz_node(JsonToFlatbuffer(
374 R"node({
375 "name": "baz"
376})node",
377 Node::MiniReflectTypeTable()));
378
379 // Local logger.
380 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_self_channel.message(),
381 &foo_node.message()));
382 EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_self_channel.message(),
383 &bar_node.message()));
384 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_self_channel.message(),
385 &baz_node.message()));
386
387 // No logger.
388 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&not_logged_channel.message(),
389 &foo_node.message()));
390 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&not_logged_channel.message(),
391 &bar_node.message()));
392 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&not_logged_channel.message(),
393 &baz_node.message()));
394
395 // Remote logger.
396 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_remote_channel.message(),
397 &foo_node.message()));
398 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_remote_channel.message(),
399 &bar_node.message()));
400 EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_remote_channel.message(),
401 &baz_node.message()));
402
403 // Separate logger.
404 EXPECT_TRUE(ChannelMessageIsLoggedOnNode(
405 &logged_on_separate_logger_node_channel.message(), &foo_node.message()));
406 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(
407 &logged_on_separate_logger_node_channel.message(), &bar_node.message()));
408 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(
409 &logged_on_separate_logger_node_channel.message(), &baz_node.message()));
410
411 // Logged in multiple places.
412 EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_both_channel.message(),
413 &foo_node.message()));
414 EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_both_channel.message(),
415 &bar_node.message()));
416 EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_both_channel.message(),
417 &baz_node.message()));
418}
419
420// Tests that our forwarding timestamps are logged helpers work as intended.
421TEST_F(ConfigurationTest, ConnectionDeliveryTimeIsLoggedOnNode) {
422 FlatbufferDetachedBuffer<Channel> logged_on_self_channel(JsonToFlatbuffer(
423 R"channel({
424 "name": "/test",
425 "type": "aos.examples.Ping",
426 "source_node": "bar",
427 "logger": "REMOTE_LOGGER",
428 "logger_node": "baz",
429 "destination_nodes": [
430 {
431 "name": "baz"
432 }
433 ]
434})channel",
435 Channel::MiniReflectTypeTable()));
436
437 FlatbufferDetachedBuffer<Channel> not_logged_channel(JsonToFlatbuffer(
438 R"channel({
439 "name": "/test",
440 "type": "aos.examples.Ping",
441 "source_node": "bar",
442 "logger": "NOT_LOGGED",
443 "destination_nodes": [
444 {
445 "name": "baz",
446 "timestamp_logger": "NOT_LOGGED"
447 }
448 ]
449})channel",
450 Channel::MiniReflectTypeTable()));
451
452 FlatbufferDetachedBuffer<Channel> logged_on_remote_channel(JsonToFlatbuffer(
453 R"channel({
454 "name": "/test",
455 "type": "aos.examples.Ping",
456 "source_node": "bar",
457 "destination_nodes": [
458 {
459 "name": "baz",
460 "timestamp_logger": "REMOTE_LOGGER",
461 "timestamp_logger_node": "bar"
462 }
463 ]
464})channel",
465 Channel::MiniReflectTypeTable()));
466
467 FlatbufferDetachedBuffer<Channel> logged_on_separate_logger_node_channel(
468 JsonToFlatbuffer(
469 R"channel({
470 "name": "/test",
471 "type": "aos.examples.Ping",
472 "source_node": "bar",
473 "logger": "REMOTE_LOGGER",
474 "logger_node": "foo",
475 "destination_nodes": [
476 {
477 "name": "baz",
478 "timestamp_logger": "REMOTE_LOGGER",
479 "timestamp_logger_node": "foo"
480 }
481 ]
482})channel",
483 Channel::MiniReflectTypeTable()));
484
485 FlatbufferDetachedBuffer<Channel> logged_on_both_channel (
486 JsonToFlatbuffer(
487 R"channel({
488 "name": "/test",
489 "type": "aos.examples.Ping",
490 "source_node": "bar",
491 "destination_nodes": [
492 {
493 "name": "baz",
494 "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER",
495 "timestamp_logger_node": "bar"
496 }
497 ]
498})channel",
499 Channel::MiniReflectTypeTable()));
500
501 FlatbufferDetachedBuffer<Node> foo_node(JsonToFlatbuffer(
502 R"node({
503 "name": "foo"
504})node",
505 Node::MiniReflectTypeTable()));
506
507 FlatbufferDetachedBuffer<Node> bar_node(JsonToFlatbuffer(
508 R"node({
509 "name": "bar"
510})node",
511 Node::MiniReflectTypeTable()));
512
513 FlatbufferDetachedBuffer<Node> baz_node(JsonToFlatbuffer(
514 R"node({
515 "name": "baz"
516})node",
517 Node::MiniReflectTypeTable()));
518
519 // Local logger.
520 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
521 &logged_on_self_channel.message(), &baz_node.message(),
522 &foo_node.message()));
523 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
524 &logged_on_self_channel.message(), &baz_node.message(),
525 &bar_node.message()));
526 EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode(
527 &logged_on_self_channel.message(), &baz_node.message(),
528 &baz_node.message()));
529
530 // No logger means.
531 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
532 &not_logged_channel.message(), &baz_node.message(), &foo_node.message()));
533 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
534 &not_logged_channel.message(), &baz_node.message(), &bar_node.message()));
535 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
536 &not_logged_channel.message(), &baz_node.message(), &baz_node.message()));
537
538 // Remote logger.
539 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
540 &logged_on_remote_channel.message(), &baz_node.message(),
541 &foo_node.message()));
542 EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode(
543 &logged_on_remote_channel.message(), &baz_node.message(),
544 &bar_node.message()));
545 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
546 &logged_on_remote_channel.message(), &baz_node.message(),
547 &baz_node.message()));
548
549 // Separate logger.
550 EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode(
551 &logged_on_separate_logger_node_channel.message(), &baz_node.message(),
552 &foo_node.message()));
553 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
554 &logged_on_separate_logger_node_channel.message(), &baz_node.message(),
555 &bar_node.message()));
556 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
557 &logged_on_separate_logger_node_channel.message(), &baz_node.message(),
558 &baz_node.message()));
559
560 // Logged on both the node and a remote node.
561 EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode(
562 &logged_on_both_channel.message(), &baz_node.message(),
563 &foo_node.message()));
564 EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode(
565 &logged_on_both_channel.message(), &baz_node.message(),
566 &bar_node.message()));
567 EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode(
568 &logged_on_both_channel.message(), &baz_node.message(),
569 &baz_node.message()));
570}
Austin Schuhe84c3ed2019-12-14 15:29:48 -0800571
572// Tests that we can deduce source nodes from a multinode config.
573TEST_F(ConfigurationTest, SourceNodeNames) {
574 FlatbufferDetachedBuffer<Configuration> config =
575 ReadConfig("aos/testdata/config1_multinode.json");
576
577 // This is a bit simplistic in that it doesn't test deduplication, but it does
578 // exercise a lot of the logic.
579 EXPECT_THAT(
580 SourceNodeNames(&config.message(), config.message().nodes()->Get(0)),
581 ::testing::ElementsAreArray({"pi2"}));
582 EXPECT_THAT(
583 SourceNodeNames(&config.message(), config.message().nodes()->Get(1)),
584 ::testing::ElementsAreArray({"pi1"}));
585}
586
587// Tests that we can deduce destination nodes from a multinode config.
588TEST_F(ConfigurationTest, DestinationNodeNames) {
589 FlatbufferDetachedBuffer<Configuration> config =
590 ReadConfig("aos/testdata/config1_multinode.json");
591
592 // This is a bit simplistic in that it doesn't test deduplication, but it does
593 // exercise a lot of the logic.
594 EXPECT_THAT(
595 DestinationNodeNames(&config.message(), config.message().nodes()->Get(0)),
596 ::testing::ElementsAreArray({"pi2"}));
597 EXPECT_THAT(
598 DestinationNodeNames(&config.message(), config.message().nodes()->Get(1)),
599 ::testing::ElementsAreArray({"pi1"}));
600}
601
Austin Schuhcb108412019-10-13 16:09:54 -0700602} // namespace testing
603} // namespace configuration
604} // namespace aos