Add and test TryMakeFetcher, TryMakeSender, and NodeHasTag helpers
Using a Fetcher for a channel on nodes where it exists and triggering
logic to handle other nodes based on whether the fetcher is valid works
well for some use cases. Add a method to EventLoop to support that
directly, instead of forcing the caller to redo the logic around whether
a channel exists and is readable. Basing similar logic off whether the
node has a given tag is also fairly common.
In the process, fill out the EventLoop tests around channels that don't
exist or aren't readable/writable a bit better.
Change-Id: I168e3c1e98adc4461a01d98360f0f0a78d24bbb5
Signed-off-by: Brian Silverman <brian.silverman@bluerivertech.com>
diff --git a/aos/configuration_test.cc b/aos/configuration_test.cc
index a73a34a..f5081d2 100644
--- a/aos/configuration_test.cc
+++ b/aos/configuration_test.cc
@@ -767,6 +767,27 @@
}
}
+// Tests that we can check if a node has a tag.
+TEST_F(ConfigurationTest, NodeHasTag) {
+ {
+ FlatbufferDetachedBuffer<Configuration> config =
+ ReadConfig(ArtifactPath("aos/testdata/good_multinode.json"));
+ const Node *pi1 = GetNode(&config.message(), "pi1");
+ const Node *pi2 = GetNode(&config.message(), "pi2");
+
+ EXPECT_TRUE(NodeHasTag(pi1, "a"));
+ EXPECT_FALSE(NodeHasTag(pi2, "a"));
+ EXPECT_FALSE(NodeHasTag(pi1, "b"));
+ EXPECT_TRUE(NodeHasTag(pi2, "b"));
+ EXPECT_TRUE(NodeHasTag(pi1, "c"));
+ EXPECT_TRUE(NodeHasTag(pi2, "c"));
+ EXPECT_FALSE(NodeHasTag(pi1, "nope"));
+ EXPECT_FALSE(NodeHasTag(pi2, "nope"));
+ }
+
+ EXPECT_TRUE(NodeHasTag(nullptr, "arglfish"));
+}
+
// Tests that we can extract a node index from a config.
TEST_F(ConfigurationTest, GetNodeIndex) {
FlatbufferDetachedBuffer<Configuration> config =