Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 1 | #include "aos/configuration.h" |
| 2 | |
| 3 | #include "absl/strings/strip.h" |
| 4 | #include "aos/json_to_flatbuffer.h" |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 5 | #include "aos/testing/flatbuffer_eq.h" |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 6 | #include "aos/testing/path.h" |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 7 | #include "aos/testing/test_logging.h" |
| 8 | #include "aos/util/file.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 9 | #include "flatbuffers/reflection.h" |
| 10 | #include "glog/logging.h" |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 11 | #include "gmock/gmock.h" |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 12 | #include "gtest/gtest.h" |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 13 | |
| 14 | namespace aos { |
| 15 | namespace configuration { |
| 16 | namespace testing { |
| 17 | |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 18 | using aos::testing::ArtifactPath; |
Austin Schuh | fb37c61 | 2022-08-11 15:24:51 -0700 | [diff] [blame^] | 19 | namespace chrono = std::chrono; |
Austin Schuh | 6660213 | 2020-02-28 13:38:37 -0800 | [diff] [blame] | 20 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 21 | class ConfigurationTest : public ::testing::Test { |
| 22 | public: |
| 23 | ConfigurationTest() { ::aos::testing::EnableTestLogging(); } |
| 24 | }; |
| 25 | |
| 26 | typedef ConfigurationTest ConfigurationDeathTest; |
| 27 | |
| 28 | // *the* expected location for all working tests. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 29 | aos::FlatbufferDetachedBuffer<Channel> ExpectedLocation() { |
| 30 | return JsonToFlatbuffer<Channel>( |
| 31 | "{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"max_size\": 5 }"); |
| 32 | } |
| 33 | |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 34 | // And for multinode setups |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 35 | aos::FlatbufferDetachedBuffer<Channel> ExpectedMultinodeLocation() { |
| 36 | return JsonToFlatbuffer<Channel>( |
| 37 | "{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"max_size\": 5, " |
| 38 | "\"source_node\": \"pi1\" }"); |
| 39 | } |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 40 | |
| 41 | // Tests that we can read and merge a configuration. |
| 42 | TEST_F(ConfigurationTest, ConfigMerge) { |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 43 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 44 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 45 | LOG(INFO) << "Read: " << FlatbufferToJson(config, {.multi_line = true}); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 46 | |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 47 | EXPECT_EQ(absl::StripSuffix(util::ReadFileToStringOrDie( |
| 48 | ArtifactPath("aos/testdata/expected.json")), |
| 49 | "\n"), |
| 50 | FlatbufferToJson(config, {.multi_line = true})); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 53 | // Tests that we can get back a ChannelIndex. |
| 54 | TEST_F(ConfigurationTest, ChannelIndex) { |
| 55 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 56 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 57 | |
| 58 | EXPECT_EQ( |
| 59 | ChannelIndex(&config.message(), config.message().channels()->Get(1u)), |
| 60 | 1u); |
| 61 | } |
| 62 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 63 | // Tests that we can read and merge a multinode configuration. |
| 64 | TEST_F(ConfigurationTest, ConfigMergeMultinode) { |
| 65 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 66 | ReadConfig(ArtifactPath("aos/testdata/config1_multinode.json")); |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 67 | LOG(INFO) << "Read: " << FlatbufferToJson(config, {.multi_line = true}); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 68 | |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 69 | EXPECT_EQ(std::string(absl::StripSuffix( |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 70 | util::ReadFileToStringOrDie( |
| 71 | ArtifactPath("aos/testdata/expected_multinode.json")), |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 72 | "\n")), |
| 73 | FlatbufferToJson(config, {.multi_line = true})); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 76 | // Tests that we sort the entries in a config so we can look entries up. |
| 77 | TEST_F(ConfigurationTest, UnsortedConfig) { |
| 78 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 79 | ReadConfig(ArtifactPath("aos/testdata/backwards.json")); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 80 | |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 81 | LOG(INFO) << "Read: " << FlatbufferToJson(config, {.multi_line = true}); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 82 | |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 83 | EXPECT_EQ(FlatbufferToJson(GetChannel(config, "/aos/robot_state", |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 84 | "aos.RobotState", "app1", nullptr)), |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 85 | "{ \"name\": \"/aos/robot_state\", \"type\": \"aos.RobotState\", " |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 86 | "\"max_size\": 5 }"); |
| 87 | } |
| 88 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 89 | // Tests that we die when a file is imported twice. |
| 90 | TEST_F(ConfigurationDeathTest, DuplicateFile) { |
| 91 | EXPECT_DEATH( |
| 92 | { |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 93 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 94 | ReadConfig(ArtifactPath("aos/testdata/config1_bad.json")); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 95 | }, |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 96 | "aos/testdata/config1_bad.json"); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Milind Upadhyay | 17098ba | 2022-04-15 22:18:50 -0700 | [diff] [blame] | 99 | // Tests that we die when we give an invalid path. |
| 100 | TEST_F(ConfigurationDeathTest, NonexistentFile) { |
| 101 | EXPECT_DEATH( |
| 102 | { |
| 103 | FlatbufferDetachedBuffer<Configuration> config = |
| 104 | ReadConfig("nonexistent/config.json"); |
| 105 | }, |
| 106 | "above error"); |
| 107 | } |
| 108 | |
| 109 | // Tests that we return std::nullopt when we give an invalid path. |
| 110 | TEST_F(ConfigurationTest, NonexistentFileOptional) { |
| 111 | std::optional<FlatbufferDetachedBuffer<Configuration>> config = |
| 112 | MaybeReadConfig("nonexistent/config.json"); |
| 113 | EXPECT_FALSE(config.has_value()); |
| 114 | } |
| 115 | |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 116 | // Tests that we reject invalid channel names. This means any channels with // |
| 117 | // in their name, a trailing /, or regex characters. |
| 118 | TEST_F(ConfigurationDeathTest, InvalidChannelName) { |
| 119 | EXPECT_DEATH( |
| 120 | { |
| 121 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 122 | ReadConfig(ArtifactPath("aos/testdata/invalid_channel_name1.json")); |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 123 | }, |
| 124 | "Channel names can't end with '/'"); |
| 125 | EXPECT_DEATH( |
| 126 | { |
| 127 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 128 | ReadConfig(ArtifactPath("aos/testdata/invalid_channel_name2.json")); |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 129 | }, |
| 130 | "Invalid channel name"); |
| 131 | EXPECT_DEATH( |
| 132 | { |
| 133 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 134 | ReadConfig(ArtifactPath("aos/testdata/invalid_channel_name3.json")); |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 135 | LOG(FATAL) << "Foo"; |
| 136 | }, |
| 137 | "Invalid channel name"); |
| 138 | } |
| 139 | |
Austin Schuh | 8d6cea8 | 2020-02-28 12:17:16 -0800 | [diff] [blame] | 140 | // Tests that we can modify a config with a json snippet. |
| 141 | TEST_F(ConfigurationTest, MergeWithConfig) { |
| 142 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 143 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 144 | LOG(INFO) << "Read: " << FlatbufferToJson(config, {.multi_line = true}); |
Austin Schuh | 8d6cea8 | 2020-02-28 12:17:16 -0800 | [diff] [blame] | 145 | |
| 146 | FlatbufferDetachedBuffer<Configuration> updated_config = |
| 147 | MergeWithConfig(&config.message(), |
| 148 | R"channel({ |
| 149 | "channels": [ |
| 150 | { |
| 151 | "name": "/foo", |
| 152 | "type": ".aos.bar", |
| 153 | "max_size": 100 |
| 154 | } |
| 155 | ] |
| 156 | })channel"); |
| 157 | |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 158 | EXPECT_EQ(absl::StripSuffix(util::ReadFileToStringOrDie(ArtifactPath( |
| 159 | "aos/testdata/expected_merge_with.json")), |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 160 | "\n"), |
| 161 | FlatbufferToJson(updated_config, {.multi_line = true})); |
Austin Schuh | 8d6cea8 | 2020-02-28 12:17:16 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 164 | // Tests that we can lookup a location, complete with maps, from a merged |
| 165 | // config. |
Austin Schuh | 40485ed | 2019-10-26 21:51:44 -0700 | [diff] [blame] | 166 | TEST_F(ConfigurationTest, GetChannel) { |
| 167 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 168 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 169 | |
| 170 | // Test a basic lookup first. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 171 | EXPECT_THAT(GetChannel(config, "/foo", ".aos.bar", "app1", nullptr), |
| 172 | aos::testing::FlatbufferEq(ExpectedLocation())); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 173 | |
| 174 | // Test that an invalid name results in nullptr back. |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 175 | EXPECT_EQ(GetChannel(config, "/invalid_name", ".aos.bar", "app1", nullptr), |
| 176 | nullptr); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 177 | |
| 178 | // Tests that a root map/rename works. And that they get processed from the |
| 179 | // bottom up. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 180 | EXPECT_THAT(GetChannel(config, "/batman", ".aos.bar", "app1", nullptr), |
| 181 | aos::testing::FlatbufferEq(ExpectedLocation())); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 182 | |
| 183 | // And then test that an application specific map/rename works. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 184 | EXPECT_THAT(GetChannel(config, "/bar", ".aos.bar", "app1", nullptr), |
| 185 | aos::testing::FlatbufferEq(ExpectedLocation())); |
| 186 | EXPECT_THAT(GetChannel(config, "/baz", ".aos.bar", "app2", nullptr), |
| 187 | aos::testing::FlatbufferEq(ExpectedLocation())); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 188 | |
| 189 | // And then test that an invalid application name gets properly ignored. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 190 | EXPECT_THAT(GetChannel(config, "/foo", ".aos.bar", "app3", nullptr), |
| 191 | aos::testing::FlatbufferEq(ExpectedLocation())); |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 192 | } |
| 193 | |
James Kuszmaul | c8503f3 | 2022-06-25 16:17:12 -0700 | [diff] [blame] | 194 | // Tests that we can do reverse-lookups of channel names. |
| 195 | TEST_F(ConfigurationTest, GetChannelAliases) { |
| 196 | FlatbufferDetachedBuffer<Configuration> config = |
| 197 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
| 198 | |
| 199 | // Test a basic lookup first. |
| 200 | EXPECT_THAT( |
| 201 | GetChannelAliases(&config.message(), "/foo", ".aos.bar", "app1", nullptr), |
| 202 | ::testing::UnorderedElementsAre("/foo", "/batman", "/bar")); |
| 203 | EXPECT_THAT( |
| 204 | GetChannelAliases(&config.message(), "/bar", ".aos.bar", "app1", nullptr), |
| 205 | ::testing::UnorderedElementsAre("/batman", "/bar")); |
| 206 | EXPECT_THAT(GetChannelAliases(&config.message(), "/batman", ".aos.bar", |
| 207 | "app1", nullptr), |
| 208 | ::testing::UnorderedElementsAre("/batman")); |
| 209 | // /bar (deliberately) does not get included because of the ordering in the |
| 210 | // map. |
| 211 | EXPECT_THAT( |
| 212 | GetChannelAliases(&config.message(), "/foo", ".aos.bar", "", nullptr), |
| 213 | ::testing::UnorderedElementsAre("/foo", "/batman")); |
| 214 | EXPECT_THAT( |
| 215 | GetChannelAliases(&config.message(), "/foo", ".aos.bar", "app2", nullptr), |
| 216 | ::testing::UnorderedElementsAre("/foo", "/batman", "/baz")); |
| 217 | } |
| 218 | |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 219 | // Tests that we can lookup a location with node specific maps. |
| 220 | TEST_F(ConfigurationTest, GetChannelMultinode) { |
| 221 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 222 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 223 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 224 | const Node *pi2 = GetNode(&config.message(), "pi2"); |
| 225 | |
| 226 | // Test a basic lookup first. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 227 | EXPECT_THAT(GetChannel(config, "/foo", ".aos.bar", "app1", pi1), |
| 228 | aos::testing::FlatbufferEq(ExpectedMultinodeLocation())); |
| 229 | EXPECT_THAT(GetChannel(config, "/foo", ".aos.bar", "app1", pi2), |
| 230 | aos::testing::FlatbufferEq(ExpectedMultinodeLocation())); |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 231 | |
| 232 | // Tests that a root map/rename works with a node specific map. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 233 | EXPECT_THAT(GetChannel(config, "/batman", ".aos.bar", "app1", pi1), |
| 234 | aos::testing::FlatbufferEq(ExpectedMultinodeLocation())); |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 235 | |
| 236 | // Tests that a root map/rename fails with a node specific map for the wrong |
| 237 | // node. |
| 238 | EXPECT_EQ(GetChannel(config, "/batman", ".aos.bar", "app1", pi2), nullptr); |
| 239 | |
| 240 | // And then test that an application specific map/rename works. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 241 | EXPECT_THAT(GetChannel(config, "/batman2", ".aos.bar", "app1", pi1), |
| 242 | aos::testing::FlatbufferEq(ExpectedMultinodeLocation())); |
| 243 | EXPECT_THAT(GetChannel(config, "/batman3", ".aos.bar", "app1", pi1), |
| 244 | aos::testing::FlatbufferEq(ExpectedMultinodeLocation())); |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 245 | |
| 246 | // And then that it fails when the node changes. |
| 247 | EXPECT_EQ(GetChannel(config, "/batman3", ".aos.bar", "app1", pi2), nullptr); |
| 248 | } |
| 249 | |
James Kuszmaul | c8503f3 | 2022-06-25 16:17:12 -0700 | [diff] [blame] | 250 | // Tests that reverse channel lookup on a multi-node config (including with |
| 251 | // wildcards) works. |
| 252 | TEST_F(ConfigurationTest, GetChannelAliasesMultinode) { |
| 253 | FlatbufferDetachedBuffer<Configuration> config = |
| 254 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
| 255 | |
| 256 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 257 | const Node *pi2 = GetNode(&config.message(), "pi2"); |
| 258 | |
| 259 | EXPECT_THAT( |
| 260 | GetChannelAliases(&config.message(), "/foo", ".aos.bar", "app1", pi1), |
| 261 | ::testing::UnorderedElementsAre("/foo", "/batman", "/batman2", "/batman3", |
| 262 | "/magic/string")); |
| 263 | |
| 264 | EXPECT_THAT( |
| 265 | GetChannelAliases(&config.message(), "/foo", ".aos.baz", "app1", pi1), |
| 266 | ::testing::UnorderedElementsAre("/foo", "/batman3", "/magic/string")); |
| 267 | |
| 268 | EXPECT_THAT( |
| 269 | GetChannelAliases(&config.message(), "/foo/testing", ".aos.bar", "", pi1), |
| 270 | ::testing::UnorderedElementsAre("/foo/testing", "/magic/string/testing")); |
| 271 | |
| 272 | EXPECT_THAT( |
| 273 | GetChannelAliases(&config.message(), "/foo/testing", ".aos.bar", "app1", |
| 274 | pi2), |
| 275 | ::testing::UnorderedElementsAre("/foo/testing", "/magic/string/testing")); |
| 276 | } |
| 277 | |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 278 | // Tests that we can lookup a location with type specific maps. |
| 279 | TEST_F(ConfigurationTest, GetChannelTypedMultinode) { |
| 280 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 281 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 282 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 283 | |
| 284 | // Test a basic lookup first. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 285 | EXPECT_THAT(GetChannel(config, "/batman", ".aos.bar", "app1", pi1), |
| 286 | aos::testing::FlatbufferEq(ExpectedMultinodeLocation())); |
Austin Schuh | bca6cf0 | 2019-12-22 17:28:34 -0800 | [diff] [blame] | 287 | |
| 288 | // Now confirm that a second message on the same name doesn't get remapped. |
| 289 | const char *kExpectedBazMultinodeLocation = |
| 290 | "{ \"name\": \"/batman\", \"type\": \".aos.baz\", \"max_size\": 5, " |
| 291 | "\"source_node\": \"pi1\" }"; |
| 292 | EXPECT_EQ( |
| 293 | FlatbufferToJson(GetChannel(config, "/batman", ".aos.baz", "app1", pi1)), |
| 294 | kExpectedBazMultinodeLocation); |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 297 | // Tests that we can lookup a location with a glob |
| 298 | TEST_F(ConfigurationTest, GetChannelGlob) { |
| 299 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 300 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 301 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 302 | |
| 303 | // Confirm that a glob with nothing after it matches. |
Austin Schuh | 1ef01ef | 2021-02-07 20:40:36 -0800 | [diff] [blame] | 304 | EXPECT_THAT(GetChannel(config, "/magic/string", ".aos.bar", "app7", pi1), |
| 305 | aos::testing::FlatbufferEq(ExpectedMultinodeLocation())); |
Austin Schuh | f1fff28 | 2020-03-28 16:57:32 -0700 | [diff] [blame] | 306 | |
| 307 | // Now confirm that glob with something following it matches and renames |
| 308 | // correctly. |
| 309 | const char *kExpectedSubfolderMultinodeLocation = |
| 310 | "{ \"name\": \"/foo/subfolder\", \"type\": \".aos.bar\", \"max_size\": " |
| 311 | "5, \"source_node\": \"pi1\" }"; |
| 312 | EXPECT_EQ(FlatbufferToJson(GetChannel(config, "/magic/string/subfolder", |
| 313 | ".aos.bar", "app7", pi1)), |
| 314 | kExpectedSubfolderMultinodeLocation); |
| 315 | } |
| 316 | |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 317 | // Tests that we reject a configuration which has a nodes list, but has channels |
| 318 | // withoout source_node filled out. |
| 319 | TEST_F(ConfigurationDeathTest, InvalidSourceNode) { |
| 320 | EXPECT_DEATH( |
| 321 | { |
| 322 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 323 | ReadConfig(ArtifactPath("aos/testdata/invalid_nodes.json")); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 324 | }, |
| 325 | "source_node"); |
| 326 | |
| 327 | EXPECT_DEATH( |
| 328 | { |
| 329 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 330 | ReadConfig(ArtifactPath("aos/testdata/invalid_source_node.json")); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 331 | }, |
| 332 | "source_node"); |
| 333 | |
| 334 | EXPECT_DEATH( |
| 335 | { |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 336 | FlatbufferDetachedBuffer<Configuration> config = ReadConfig( |
| 337 | ArtifactPath("aos/testdata/invalid_destination_node.json")); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 338 | }, |
| 339 | "destination_nodes"); |
| 340 | |
| 341 | EXPECT_DEATH( |
| 342 | { |
| 343 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 344 | ReadConfig(ArtifactPath("aos/testdata/self_forward.json")); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 345 | }, |
| 346 | "forwarding data to itself"); |
| 347 | } |
| 348 | |
| 349 | // Tests that our node writeable helpers work as intended. |
| 350 | TEST_F(ConfigurationTest, ChannelIsSendableOnNode) { |
| 351 | FlatbufferDetachedBuffer<Channel> good_channel(JsonToFlatbuffer( |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 352 | R"channel({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 353 | "name": "/test", |
| 354 | "type": "aos.examples.Ping", |
| 355 | "source_node": "foo" |
| 356 | })channel", |
| 357 | Channel::MiniReflectTypeTable())); |
| 358 | |
| 359 | FlatbufferDetachedBuffer<Channel> bad_channel(JsonToFlatbuffer( |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 360 | R"channel({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 361 | "name": "/test", |
| 362 | "type": "aos.examples.Ping", |
| 363 | "source_node": "bar" |
| 364 | })channel", |
| 365 | Channel::MiniReflectTypeTable())); |
| 366 | |
| 367 | FlatbufferDetachedBuffer<Node> node(JsonToFlatbuffer( |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 368 | R"node({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 369 | "name": "foo" |
| 370 | })node", |
| 371 | Node::MiniReflectTypeTable())); |
| 372 | |
| 373 | EXPECT_TRUE( |
| 374 | ChannelIsSendableOnNode(&good_channel.message(), &node.message())); |
| 375 | EXPECT_FALSE( |
| 376 | ChannelIsSendableOnNode(&bad_channel.message(), &node.message())); |
| 377 | } |
| 378 | |
| 379 | // Tests that our node readable and writeable helpers work as intended. |
| 380 | TEST_F(ConfigurationTest, ChannelIsReadableOnNode) { |
| 381 | FlatbufferDetachedBuffer<Channel> good_channel(JsonToFlatbuffer( |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 382 | R"channel({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 383 | "name": "/test", |
| 384 | "type": "aos.examples.Ping", |
| 385 | "source_node": "bar", |
| 386 | "destination_nodes": [ |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 387 | { |
| 388 | "name": "baz" |
| 389 | }, |
| 390 | { |
| 391 | "name": "foo" |
| 392 | } |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 393 | ] |
| 394 | })channel", |
| 395 | Channel::MiniReflectTypeTable())); |
| 396 | |
| 397 | FlatbufferDetachedBuffer<Channel> bad_channel1(JsonToFlatbuffer( |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 398 | R"channel({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 399 | "name": "/test", |
| 400 | "type": "aos.examples.Ping", |
| 401 | "source_node": "bar" |
| 402 | })channel", |
| 403 | Channel::MiniReflectTypeTable())); |
| 404 | |
| 405 | FlatbufferDetachedBuffer<Channel> bad_channel2(JsonToFlatbuffer( |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 406 | R"channel({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 407 | "name": "/test", |
| 408 | "type": "aos.examples.Ping", |
| 409 | "source_node": "bar", |
| 410 | "destination_nodes": [ |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 411 | { |
| 412 | "name": "baz" |
| 413 | } |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 414 | ] |
| 415 | })channel", |
| 416 | Channel::MiniReflectTypeTable())); |
| 417 | |
| 418 | FlatbufferDetachedBuffer<Node> node(JsonToFlatbuffer( |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 419 | R"node({ |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 420 | "name": "foo" |
| 421 | })node", |
| 422 | Node::MiniReflectTypeTable())); |
| 423 | |
| 424 | EXPECT_TRUE( |
| 425 | ChannelIsReadableOnNode(&good_channel.message(), &node.message())); |
| 426 | EXPECT_FALSE( |
| 427 | ChannelIsReadableOnNode(&bad_channel1.message(), &node.message())); |
| 428 | EXPECT_FALSE( |
| 429 | ChannelIsReadableOnNode(&bad_channel2.message(), &node.message())); |
| 430 | } |
| 431 | |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 432 | // Tests that our node message is logged helpers work as intended. |
| 433 | TEST_F(ConfigurationTest, ChannelMessageIsLoggedOnNode) { |
| 434 | FlatbufferDetachedBuffer<Channel> logged_on_self_channel(JsonToFlatbuffer( |
| 435 | R"channel({ |
| 436 | "name": "/test", |
| 437 | "type": "aos.examples.Ping", |
| 438 | "source_node": "bar", |
| 439 | "destination_nodes": [ |
| 440 | { |
| 441 | "name": "baz" |
| 442 | } |
| 443 | ] |
| 444 | })channel", |
| 445 | Channel::MiniReflectTypeTable())); |
Austin Schuh | 217a978 | 2019-12-21 23:02:50 -0800 | [diff] [blame] | 446 | |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 447 | FlatbufferDetachedBuffer<Channel> not_logged_channel(JsonToFlatbuffer( |
| 448 | R"channel({ |
| 449 | "name": "/test", |
| 450 | "type": "aos.examples.Ping", |
| 451 | "source_node": "bar", |
| 452 | "logger": "NOT_LOGGED", |
| 453 | "destination_nodes": [ |
| 454 | { |
| 455 | "name": "baz", |
| 456 | "timestamp_logger": "LOCAL_LOGGER" |
| 457 | } |
| 458 | ] |
| 459 | })channel", |
| 460 | Channel::MiniReflectTypeTable())); |
| 461 | |
| 462 | FlatbufferDetachedBuffer<Channel> logged_on_remote_channel(JsonToFlatbuffer( |
| 463 | R"channel({ |
| 464 | "name": "/test", |
| 465 | "type": "aos.examples.Ping", |
| 466 | "source_node": "bar", |
| 467 | "logger": "REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 468 | "logger_nodes": ["baz"], |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 469 | "destination_nodes": [ |
| 470 | { |
| 471 | "name": "baz" |
| 472 | } |
| 473 | ] |
| 474 | })channel", |
| 475 | Channel::MiniReflectTypeTable())); |
| 476 | |
| 477 | FlatbufferDetachedBuffer<Channel> logged_on_separate_logger_node_channel( |
| 478 | JsonToFlatbuffer( |
| 479 | R"channel({ |
| 480 | "name": "/test", |
| 481 | "type": "aos.examples.Ping", |
| 482 | "source_node": "bar", |
| 483 | "logger": "REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 484 | "logger_nodes": ["foo"], |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 485 | "destination_nodes": [ |
| 486 | { |
| 487 | "name": "baz" |
| 488 | } |
| 489 | ] |
| 490 | })channel", |
| 491 | Channel::MiniReflectTypeTable())); |
| 492 | |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 493 | FlatbufferDetachedBuffer<Channel> logged_on_both_channel(JsonToFlatbuffer( |
| 494 | R"channel({ |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 495 | "name": "/test", |
| 496 | "type": "aos.examples.Ping", |
| 497 | "source_node": "bar", |
| 498 | "logger": "LOCAL_AND_REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 499 | "logger_nodes": ["baz"], |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 500 | "destination_nodes": [ |
| 501 | { |
| 502 | "name": "baz" |
| 503 | } |
| 504 | ] |
| 505 | })channel", |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 506 | Channel::MiniReflectTypeTable())); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 507 | |
| 508 | FlatbufferDetachedBuffer<Node> foo_node(JsonToFlatbuffer( |
| 509 | R"node({ |
| 510 | "name": "foo" |
| 511 | })node", |
| 512 | Node::MiniReflectTypeTable())); |
| 513 | |
| 514 | FlatbufferDetachedBuffer<Node> bar_node(JsonToFlatbuffer( |
| 515 | R"node({ |
| 516 | "name": "bar" |
| 517 | })node", |
| 518 | Node::MiniReflectTypeTable())); |
| 519 | |
| 520 | FlatbufferDetachedBuffer<Node> baz_node(JsonToFlatbuffer( |
| 521 | R"node({ |
| 522 | "name": "baz" |
| 523 | })node", |
| 524 | Node::MiniReflectTypeTable())); |
| 525 | |
| 526 | // Local logger. |
| 527 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_self_channel.message(), |
| 528 | &foo_node.message())); |
| 529 | EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_self_channel.message(), |
| 530 | &bar_node.message())); |
| 531 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_self_channel.message(), |
| 532 | &baz_node.message())); |
Austin Schuh | 48e9450 | 2021-06-18 18:35:53 -0700 | [diff] [blame] | 533 | EXPECT_TRUE( |
| 534 | ChannelMessageIsLoggedOnNode(&logged_on_self_channel.message(), nullptr)); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 535 | |
| 536 | // No logger. |
| 537 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(¬_logged_channel.message(), |
| 538 | &foo_node.message())); |
| 539 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(¬_logged_channel.message(), |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 540 | &bar_node.message())); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 541 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(¬_logged_channel.message(), |
| 542 | &baz_node.message())); |
Austin Schuh | 48e9450 | 2021-06-18 18:35:53 -0700 | [diff] [blame] | 543 | EXPECT_FALSE( |
| 544 | ChannelMessageIsLoggedOnNode(¬_logged_channel.message(), nullptr)); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 545 | |
| 546 | // Remote logger. |
| 547 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_remote_channel.message(), |
| 548 | &foo_node.message())); |
| 549 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_remote_channel.message(), |
| 550 | &bar_node.message())); |
| 551 | EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_remote_channel.message(), |
| 552 | &baz_node.message())); |
| 553 | |
| 554 | // Separate logger. |
| 555 | EXPECT_TRUE(ChannelMessageIsLoggedOnNode( |
| 556 | &logged_on_separate_logger_node_channel.message(), &foo_node.message())); |
| 557 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode( |
| 558 | &logged_on_separate_logger_node_channel.message(), &bar_node.message())); |
| 559 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode( |
| 560 | &logged_on_separate_logger_node_channel.message(), &baz_node.message())); |
| 561 | |
| 562 | // Logged in multiple places. |
| 563 | EXPECT_FALSE(ChannelMessageIsLoggedOnNode(&logged_on_both_channel.message(), |
| 564 | &foo_node.message())); |
| 565 | EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_both_channel.message(), |
| 566 | &bar_node.message())); |
| 567 | EXPECT_TRUE(ChannelMessageIsLoggedOnNode(&logged_on_both_channel.message(), |
| 568 | &baz_node.message())); |
| 569 | } |
| 570 | |
Austin Schuh | 48e9450 | 2021-06-18 18:35:53 -0700 | [diff] [blame] | 571 | // Tests that our node message is logged helpers work as intended. |
| 572 | TEST_F(ConfigurationDeathTest, ChannelMessageIsLoggedOnNode) { |
| 573 | FlatbufferDetachedBuffer<Channel> logged_on_both_channel(JsonToFlatbuffer( |
| 574 | R"channel({ |
| 575 | "name": "/test", |
| 576 | "type": "aos.examples.Ping", |
| 577 | "source_node": "bar", |
| 578 | "logger": "LOCAL_AND_REMOTE_LOGGER", |
| 579 | "logger_nodes": ["baz"], |
| 580 | "destination_nodes": [ |
| 581 | { |
| 582 | "name": "baz" |
| 583 | } |
| 584 | ] |
| 585 | })channel", |
| 586 | Channel::MiniReflectTypeTable())); |
| 587 | |
| 588 | FlatbufferDetachedBuffer<Channel> logged_on_separate_logger_node_channel( |
| 589 | JsonToFlatbuffer( |
| 590 | R"channel({ |
| 591 | "name": "/test", |
| 592 | "type": "aos.examples.Ping", |
| 593 | "source_node": "bar", |
| 594 | "logger": "REMOTE_LOGGER", |
| 595 | "logger_nodes": ["foo"], |
| 596 | "destination_nodes": [ |
| 597 | { |
| 598 | "name": "baz" |
| 599 | } |
| 600 | ] |
| 601 | })channel", |
| 602 | Channel::MiniReflectTypeTable())); |
| 603 | |
| 604 | EXPECT_DEATH( |
| 605 | { |
| 606 | ChannelMessageIsLoggedOnNode(&logged_on_both_channel.message(), |
| 607 | nullptr); |
| 608 | }, |
| 609 | "Unsupported logging configuration in a single node world"); |
| 610 | EXPECT_DEATH( |
| 611 | { |
| 612 | ChannelMessageIsLoggedOnNode( |
| 613 | &logged_on_separate_logger_node_channel.message(), nullptr); |
| 614 | }, |
| 615 | "Unsupported logging configuration in a single node world"); |
| 616 | } |
| 617 | |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 618 | // Tests that our forwarding timestamps are logged helpers work as intended. |
| 619 | TEST_F(ConfigurationTest, ConnectionDeliveryTimeIsLoggedOnNode) { |
| 620 | FlatbufferDetachedBuffer<Channel> logged_on_self_channel(JsonToFlatbuffer( |
| 621 | R"channel({ |
| 622 | "name": "/test", |
| 623 | "type": "aos.examples.Ping", |
| 624 | "source_node": "bar", |
| 625 | "logger": "REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 626 | "logger_nodes": ["baz"], |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 627 | "destination_nodes": [ |
| 628 | { |
| 629 | "name": "baz" |
| 630 | } |
| 631 | ] |
| 632 | })channel", |
| 633 | Channel::MiniReflectTypeTable())); |
| 634 | |
| 635 | FlatbufferDetachedBuffer<Channel> not_logged_channel(JsonToFlatbuffer( |
| 636 | R"channel({ |
| 637 | "name": "/test", |
| 638 | "type": "aos.examples.Ping", |
| 639 | "source_node": "bar", |
| 640 | "logger": "NOT_LOGGED", |
| 641 | "destination_nodes": [ |
| 642 | { |
| 643 | "name": "baz", |
| 644 | "timestamp_logger": "NOT_LOGGED" |
| 645 | } |
| 646 | ] |
| 647 | })channel", |
| 648 | Channel::MiniReflectTypeTable())); |
| 649 | |
| 650 | FlatbufferDetachedBuffer<Channel> logged_on_remote_channel(JsonToFlatbuffer( |
| 651 | R"channel({ |
| 652 | "name": "/test", |
| 653 | "type": "aos.examples.Ping", |
| 654 | "source_node": "bar", |
| 655 | "destination_nodes": [ |
| 656 | { |
| 657 | "name": "baz", |
| 658 | "timestamp_logger": "REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 659 | "timestamp_logger_nodes": ["bar"] |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 660 | } |
| 661 | ] |
| 662 | })channel", |
| 663 | Channel::MiniReflectTypeTable())); |
| 664 | |
| 665 | FlatbufferDetachedBuffer<Channel> logged_on_separate_logger_node_channel( |
| 666 | JsonToFlatbuffer( |
| 667 | R"channel({ |
| 668 | "name": "/test", |
| 669 | "type": "aos.examples.Ping", |
| 670 | "source_node": "bar", |
| 671 | "logger": "REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 672 | "logger_nodes": ["foo"], |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 673 | "destination_nodes": [ |
| 674 | { |
| 675 | "name": "baz", |
| 676 | "timestamp_logger": "REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 677 | "timestamp_logger_nodes": ["foo"] |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 678 | } |
| 679 | ] |
| 680 | })channel", |
| 681 | Channel::MiniReflectTypeTable())); |
| 682 | |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 683 | FlatbufferDetachedBuffer<Channel> logged_on_both_channel(JsonToFlatbuffer( |
| 684 | R"channel({ |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 685 | "name": "/test", |
| 686 | "type": "aos.examples.Ping", |
| 687 | "source_node": "bar", |
| 688 | "destination_nodes": [ |
| 689 | { |
| 690 | "name": "baz", |
| 691 | "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", |
Austin Schuh | da40e47 | 2020-03-28 15:15:29 -0700 | [diff] [blame] | 692 | "timestamp_logger_nodes": ["bar"] |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 693 | } |
| 694 | ] |
| 695 | })channel", |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 696 | Channel::MiniReflectTypeTable())); |
Austin Schuh | 719946b | 2019-12-28 14:51:01 -0800 | [diff] [blame] | 697 | |
| 698 | FlatbufferDetachedBuffer<Node> foo_node(JsonToFlatbuffer( |
| 699 | R"node({ |
| 700 | "name": "foo" |
| 701 | })node", |
| 702 | Node::MiniReflectTypeTable())); |
| 703 | |
| 704 | FlatbufferDetachedBuffer<Node> bar_node(JsonToFlatbuffer( |
| 705 | R"node({ |
| 706 | "name": "bar" |
| 707 | })node", |
| 708 | Node::MiniReflectTypeTable())); |
| 709 | |
| 710 | FlatbufferDetachedBuffer<Node> baz_node(JsonToFlatbuffer( |
| 711 | R"node({ |
| 712 | "name": "baz" |
| 713 | })node", |
| 714 | Node::MiniReflectTypeTable())); |
| 715 | |
| 716 | // Local logger. |
| 717 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 718 | &logged_on_self_channel.message(), &baz_node.message(), |
| 719 | &foo_node.message())); |
| 720 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 721 | &logged_on_self_channel.message(), &baz_node.message(), |
| 722 | &bar_node.message())); |
| 723 | EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 724 | &logged_on_self_channel.message(), &baz_node.message(), |
| 725 | &baz_node.message())); |
| 726 | |
| 727 | // No logger means. |
| 728 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 729 | ¬_logged_channel.message(), &baz_node.message(), &foo_node.message())); |
| 730 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 731 | ¬_logged_channel.message(), &baz_node.message(), &bar_node.message())); |
| 732 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 733 | ¬_logged_channel.message(), &baz_node.message(), &baz_node.message())); |
| 734 | |
| 735 | // Remote logger. |
| 736 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 737 | &logged_on_remote_channel.message(), &baz_node.message(), |
| 738 | &foo_node.message())); |
| 739 | EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 740 | &logged_on_remote_channel.message(), &baz_node.message(), |
| 741 | &bar_node.message())); |
| 742 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 743 | &logged_on_remote_channel.message(), &baz_node.message(), |
| 744 | &baz_node.message())); |
| 745 | |
| 746 | // Separate logger. |
| 747 | EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 748 | &logged_on_separate_logger_node_channel.message(), &baz_node.message(), |
| 749 | &foo_node.message())); |
| 750 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 751 | &logged_on_separate_logger_node_channel.message(), &baz_node.message(), |
| 752 | &bar_node.message())); |
| 753 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 754 | &logged_on_separate_logger_node_channel.message(), &baz_node.message(), |
| 755 | &baz_node.message())); |
| 756 | |
| 757 | // Logged on both the node and a remote node. |
| 758 | EXPECT_FALSE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 759 | &logged_on_both_channel.message(), &baz_node.message(), |
| 760 | &foo_node.message())); |
| 761 | EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 762 | &logged_on_both_channel.message(), &baz_node.message(), |
| 763 | &bar_node.message())); |
| 764 | EXPECT_TRUE(ConnectionDeliveryTimeIsLoggedOnNode( |
| 765 | &logged_on_both_channel.message(), &baz_node.message(), |
| 766 | &baz_node.message())); |
| 767 | } |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 768 | |
| 769 | // Tests that we can deduce source nodes from a multinode config. |
| 770 | TEST_F(ConfigurationTest, SourceNodeNames) { |
| 771 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 772 | ReadConfig(ArtifactPath("aos/testdata/config1_multinode.json")); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 773 | |
| 774 | // This is a bit simplistic in that it doesn't test deduplication, but it does |
| 775 | // exercise a lot of the logic. |
| 776 | EXPECT_THAT( |
| 777 | SourceNodeNames(&config.message(), config.message().nodes()->Get(0)), |
| 778 | ::testing::ElementsAreArray({"pi2"})); |
| 779 | EXPECT_THAT( |
| 780 | SourceNodeNames(&config.message(), config.message().nodes()->Get(1)), |
| 781 | ::testing::ElementsAreArray({"pi1"})); |
| 782 | } |
| 783 | |
| 784 | // Tests that we can deduce destination nodes from a multinode config. |
| 785 | TEST_F(ConfigurationTest, DestinationNodeNames) { |
| 786 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 787 | ReadConfig(ArtifactPath("aos/testdata/config1_multinode.json")); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 788 | |
| 789 | // This is a bit simplistic in that it doesn't test deduplication, but it does |
| 790 | // exercise a lot of the logic. |
| 791 | EXPECT_THAT( |
| 792 | DestinationNodeNames(&config.message(), config.message().nodes()->Get(0)), |
| 793 | ::testing::ElementsAreArray({"pi2"})); |
| 794 | EXPECT_THAT( |
| 795 | DestinationNodeNames(&config.message(), config.message().nodes()->Get(1)), |
| 796 | ::testing::ElementsAreArray({"pi1"})); |
| 797 | } |
| 798 | |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 799 | // Tests that we can pull out all the nodes. |
| 800 | TEST_F(ConfigurationTest, GetNodes) { |
| 801 | { |
| 802 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 803 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 804 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 805 | const Node *pi2 = GetNode(&config.message(), "pi2"); |
| 806 | |
| 807 | EXPECT_THAT(GetNodes(&config.message()), ::testing::ElementsAre(pi1, pi2)); |
| 808 | } |
| 809 | |
| 810 | { |
| 811 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 812 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 813 | EXPECT_THAT(GetNodes(&config.message()), ::testing::ElementsAre(nullptr)); |
| 814 | } |
| 815 | } |
| 816 | |
Austin Schuh | 6546533 | 2020-11-05 17:36:53 -0800 | [diff] [blame] | 817 | // Tests that we can pull out all the nodes with a tag. |
| 818 | TEST_F(ConfigurationTest, GetNodesWithTag) { |
| 819 | { |
| 820 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 821 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | 6546533 | 2020-11-05 17:36:53 -0800 | [diff] [blame] | 822 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 823 | const Node *pi2 = GetNode(&config.message(), "pi2"); |
| 824 | |
| 825 | EXPECT_THAT(GetNodesWithTag(&config.message(), "a"), |
| 826 | ::testing::ElementsAre(pi1)); |
| 827 | EXPECT_THAT(GetNodesWithTag(&config.message(), "b"), |
| 828 | ::testing::ElementsAre(pi2)); |
| 829 | EXPECT_THAT(GetNodesWithTag(&config.message(), "c"), |
| 830 | ::testing::ElementsAre(pi1, pi2)); |
| 831 | } |
| 832 | |
| 833 | { |
| 834 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 835 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
Austin Schuh | 6546533 | 2020-11-05 17:36:53 -0800 | [diff] [blame] | 836 | EXPECT_THAT(GetNodesWithTag(&config.message(), "arglfish"), |
| 837 | ::testing::ElementsAre(nullptr)); |
| 838 | } |
| 839 | } |
| 840 | |
Brian Silverman | 631b626 | 2021-11-10 12:25:08 -0800 | [diff] [blame] | 841 | // Tests that we can check if a node has a tag. |
| 842 | TEST_F(ConfigurationTest, NodeHasTag) { |
| 843 | { |
| 844 | FlatbufferDetachedBuffer<Configuration> config = |
| 845 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
| 846 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 847 | const Node *pi2 = GetNode(&config.message(), "pi2"); |
| 848 | |
| 849 | EXPECT_TRUE(NodeHasTag(pi1, "a")); |
| 850 | EXPECT_FALSE(NodeHasTag(pi2, "a")); |
| 851 | EXPECT_FALSE(NodeHasTag(pi1, "b")); |
| 852 | EXPECT_TRUE(NodeHasTag(pi2, "b")); |
| 853 | EXPECT_TRUE(NodeHasTag(pi1, "c")); |
| 854 | EXPECT_TRUE(NodeHasTag(pi2, "c")); |
| 855 | EXPECT_FALSE(NodeHasTag(pi1, "nope")); |
| 856 | EXPECT_FALSE(NodeHasTag(pi2, "nope")); |
| 857 | } |
| 858 | |
| 859 | EXPECT_TRUE(NodeHasTag(nullptr, "arglfish")); |
| 860 | } |
| 861 | |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 862 | // Tests that we can extract a node index from a config. |
| 863 | TEST_F(ConfigurationTest, GetNodeIndex) { |
| 864 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 865 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | 04408fc | 2020-02-16 21:48:54 -0800 | [diff] [blame] | 866 | FlatbufferDetachedBuffer<Configuration> config2 = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 867 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 868 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 869 | const Node *pi2 = GetNode(&config.message(), "pi2"); |
| 870 | |
Austin Schuh | 04408fc | 2020-02-16 21:48:54 -0800 | [diff] [blame] | 871 | // Try the normal case. |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 872 | EXPECT_EQ(GetNodeIndex(&config.message(), pi1), 0); |
| 873 | EXPECT_EQ(GetNodeIndex(&config.message(), pi2), 1); |
Austin Schuh | 04408fc | 2020-02-16 21:48:54 -0800 | [diff] [blame] | 874 | |
| 875 | // Now try if we have node pointers from a different message. |
| 876 | EXPECT_EQ(GetNodeIndex(&config2.message(), pi1), 0); |
| 877 | EXPECT_EQ(GetNodeIndex(&config2.message(), pi2), 1); |
| 878 | |
| 879 | // And now try string names. |
| 880 | EXPECT_EQ(GetNodeIndex(&config2.message(), pi1->name()->string_view()), 0); |
| 881 | EXPECT_EQ(GetNodeIndex(&config2.message(), pi2->name()->string_view()), 1); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | // Tests that GetNodeOrDie handles both single and multi-node worlds and returns |
| 885 | // valid nodes. |
| 886 | TEST_F(ConfigurationDeathTest, GetNodeOrDie) { |
| 887 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 888 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 889 | FlatbufferDetachedBuffer<Configuration> config2 = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 890 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 891 | { |
| 892 | // Simple case, nullptr -> nullptr |
| 893 | FlatbufferDetachedBuffer<Configuration> single_node_config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 894 | ReadConfig(ArtifactPath("aos/testdata/config1.json")); |
Austin Schuh | c9e10ec | 2020-01-26 16:08:28 -0800 | [diff] [blame] | 895 | EXPECT_EQ(nullptr, GetNodeOrDie(&single_node_config.message(), nullptr)); |
| 896 | |
| 897 | // Confirm that we die when a node is passed in. |
| 898 | EXPECT_DEATH( |
| 899 | { |
| 900 | GetNodeOrDie(&single_node_config.message(), |
| 901 | config.message().nodes()->Get(0)); |
| 902 | }, |
| 903 | "Provided a node in a single node world."); |
| 904 | } |
| 905 | |
| 906 | const Node *pi1 = GetNode(&config.message(), "pi1"); |
| 907 | // Now try a lookup using a node from a different instance of the config. |
| 908 | EXPECT_EQ(pi1, |
| 909 | GetNodeOrDie(&config.message(), config2.message().nodes()->Get(0))); |
| 910 | } |
| 911 | |
Brian Silverman | aa2633f | 2020-02-17 21:04:14 -0800 | [diff] [blame] | 912 | TEST_F(ConfigurationTest, GetNodeFromHostname) { |
| 913 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 914 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
Brian Silverman | aa2633f | 2020-02-17 21:04:14 -0800 | [diff] [blame] | 915 | EXPECT_EQ("pi1", |
| 916 | CHECK_NOTNULL(GetNodeFromHostname(&config.message(), "raspberrypi")) |
| 917 | ->name() |
| 918 | ->string_view()); |
| 919 | EXPECT_EQ("pi2", CHECK_NOTNULL( |
| 920 | GetNodeFromHostname(&config.message(), "raspberrypi2")) |
| 921 | ->name() |
| 922 | ->string_view()); |
| 923 | EXPECT_EQ(nullptr, GetNodeFromHostname(&config.message(), "raspberrypi3")); |
| 924 | EXPECT_EQ(nullptr, GetNodeFromHostname(&config.message(), "localhost")); |
| 925 | EXPECT_EQ(nullptr, GetNodeFromHostname(&config.message(), "3")); |
| 926 | } |
| 927 | |
| 928 | TEST_F(ConfigurationTest, GetNodeFromHostnames) { |
| 929 | FlatbufferDetachedBuffer<Configuration> config = |
Austin Schuh | 373f176 | 2021-06-02 21:07:09 -0700 | [diff] [blame] | 930 | ReadConfig(ArtifactPath("aos/testdata/good_multinode_hostnames.json")); |
Brian Silverman | aa2633f | 2020-02-17 21:04:14 -0800 | [diff] [blame] | 931 | EXPECT_EQ("pi1", |
| 932 | CHECK_NOTNULL(GetNodeFromHostname(&config.message(), "raspberrypi")) |
| 933 | ->name() |
| 934 | ->string_view()); |
| 935 | EXPECT_EQ("pi2", CHECK_NOTNULL( |
| 936 | GetNodeFromHostname(&config.message(), "raspberrypi2")) |
| 937 | ->name() |
| 938 | ->string_view()); |
| 939 | EXPECT_EQ("pi2", CHECK_NOTNULL( |
| 940 | GetNodeFromHostname(&config.message(), "raspberrypi3")) |
| 941 | ->name() |
| 942 | ->string_view()); |
Ravago Jones | cf453ab | 2020-05-06 21:14:53 -0700 | [diff] [blame] | 943 | EXPECT_EQ("pi2", |
| 944 | CHECK_NOTNULL(GetNodeFromHostname(&config.message(), "other")) |
| 945 | ->name() |
| 946 | ->string_view()); |
Brian Silverman | aa2633f | 2020-02-17 21:04:14 -0800 | [diff] [blame] | 947 | EXPECT_EQ(nullptr, GetNodeFromHostname(&config.message(), "raspberrypi4")); |
| 948 | EXPECT_EQ(nullptr, GetNodeFromHostname(&config.message(), "localhost")); |
| 949 | EXPECT_EQ(nullptr, GetNodeFromHostname(&config.message(), "3")); |
| 950 | } |
| 951 | |
Austin Schuh | fc7b6a0 | 2021-07-12 21:19:07 -0700 | [diff] [blame] | 952 | // Tests that SourceNodeIndex reasonably handles a multi-node log file. |
| 953 | TEST_F(ConfigurationTest, SourceNodeIndex) { |
| 954 | FlatbufferDetachedBuffer<Configuration> config = |
| 955 | ReadConfig(ArtifactPath("aos/testdata/good_multinode.json")); |
| 956 | std::vector<size_t> result = SourceNodeIndex(&config.message()); |
| 957 | |
| 958 | EXPECT_THAT(result, ::testing::ElementsAreArray({0, 1, 0, 0})); |
| 959 | } |
| 960 | |
Austin Schuh | 5e95bd6 | 2021-10-11 18:40:22 -0700 | [diff] [blame] | 961 | // Tests that we reject invalid logging configurations. |
| 962 | TEST_F(ConfigurationDeathTest, InvalidLoggerConfig) { |
| 963 | EXPECT_DEATH( |
| 964 | { |
Milind Upadhyay | 17098ba | 2022-04-15 22:18:50 -0700 | [diff] [blame] | 965 | FlatbufferDetachedBuffer<Configuration> config = ReadConfig( |
| 966 | ArtifactPath("aos/testdata/invalid_logging_configuration.json")); |
Austin Schuh | 5e95bd6 | 2021-10-11 18:40:22 -0700 | [diff] [blame] | 967 | }, |
| 968 | "Logging timestamps without data"); |
| 969 | } |
| 970 | |
Austin Schuh | a156fb2 | 2021-10-11 19:23:21 -0700 | [diff] [blame] | 971 | // Tests that we reject duplicate timestamp destination node configurations. |
| 972 | TEST_F(ConfigurationDeathTest, DuplicateTimestampDestinationNodes) { |
| 973 | EXPECT_DEATH( |
| 974 | { |
| 975 | FlatbufferDetachedBuffer<Configuration> config = ReadConfig( |
| 976 | ArtifactPath("aos/testdata/duplicate_destination_nodes.json")); |
| 977 | }, |
| 978 | "Found duplicate timestamp_logger_nodes in"); |
| 979 | } |
| 980 | |
| 981 | // Tests that we reject duplicate logger node configurations for a channel's |
| 982 | // data. |
| 983 | TEST_F(ConfigurationDeathTest, DuplicateLoggerNodes) { |
| 984 | EXPECT_DEATH( |
| 985 | { |
| 986 | FlatbufferDetachedBuffer<Configuration> config = ReadConfig( |
| 987 | ArtifactPath("aos/testdata/duplicate_logger_nodes.json")); |
| 988 | }, |
| 989 | "Found duplicate logger_nodes in"); |
| 990 | } |
| 991 | |
Austin Schuh | fb37c61 | 2022-08-11 15:24:51 -0700 | [diff] [blame^] | 992 | // Tests that we properly compute the queue size for the provided duration. |
| 993 | TEST_F(ConfigurationTest, QueueSize) { |
| 994 | EXPECT_EQ(QueueSize(100, chrono::seconds(2)), 200); |
| 995 | EXPECT_EQ(QueueSize(200, chrono::seconds(2)), 400); |
| 996 | EXPECT_EQ(QueueSize(100, chrono::seconds(6)), 600); |
| 997 | EXPECT_EQ(QueueSize(100, chrono::milliseconds(10)), 1); |
| 998 | EXPECT_EQ(QueueSize(100, chrono::milliseconds(10) - chrono::nanoseconds(1)), |
| 999 | 1); |
| 1000 | EXPECT_EQ(QueueSize(100, chrono::milliseconds(10) - chrono::nanoseconds(2)), |
| 1001 | 1); |
| 1002 | } |
| 1003 | |
| 1004 | // Tests that we compute scratch buffer size correctly too. |
| 1005 | TEST_F(ConfigurationTest, QueueScratchBufferSize) { |
| 1006 | const aos::FlatbufferDetachedBuffer<Channel> channel = |
| 1007 | JsonToFlatbuffer<Channel>( |
| 1008 | "{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"num_readers\": 5, " |
| 1009 | "\"num_senders\": 10 }"); |
| 1010 | |
| 1011 | EXPECT_EQ(QueueScratchBufferSize(&channel.message()), 15); |
| 1012 | } |
| 1013 | |
Austin Schuh | cb10841 | 2019-10-13 16:09:54 -0700 | [diff] [blame] | 1014 | } // namespace testing |
| 1015 | } // namespace configuration |
| 1016 | } // namespace aos |