[ntcore] Add subscriber option to exclude single publisher

This enables limited self-exclusion for entries seeing their own changes
or similarly with a pub/sub pair.
This commit is contained in:
Peter Johnson
2022-12-05 23:00:50 -08:00
parent b0e4053087
commit 342c375a71
7 changed files with 131 additions and 9 deletions

View File

@@ -867,4 +867,50 @@ TEST_F(LocalStorageTest, ReadQueueLocalRemote) {
EXPECT_THAT(storage.ReadQueueDouble(subLocal), IsEmpty());
}
TEST_F(LocalStorageTest, SubExcludePub) {
EXPECT_CALL(network, Subscribe(_, _, _)).Times(2);
EXPECT_CALL(network, Publish(_, _, _, _, _, _)).Times(1);
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
auto subActive = storage.Subscribe(fooTopic, NT_DOUBLE, "double", {});
auto subExclude = storage.Subscribe(fooTopic, NT_DOUBLE, "double",
{{PubSubOption::ExcludePublisher(pub)}});
auto remoteTopic =
storage.NetworkAnnounce("foo", "double", wpi::json::object(), 0);
// local set
EXPECT_CALL(network, SetValue(_, _));
storage.SetEntryValue(pub, Value::MakeDouble(1.0, 50));
EXPECT_THAT(storage.ReadQueueDouble(subActive),
ElementsAre(TSEq<TimestampedDouble>(1.0, 50)));
EXPECT_THAT(storage.ReadQueueDouble(subExclude), IsEmpty());
// network set
storage.NetworkSetValue(remoteTopic, Value::MakeDouble(2.0, 60));
EXPECT_THAT(storage.ReadQueueDouble(subActive),
ElementsAre(TSEq<TimestampedDouble>(2.0, 60)));
EXPECT_THAT(storage.ReadQueueDouble(subExclude),
ElementsAre(TSEq<TimestampedDouble>(2.0, 60)));
}
TEST_F(LocalStorageTest, EntryExcludeSelf) {
EXPECT_CALL(network, Subscribe(_, _, _));
auto entry = storage.GetEntry(fooTopic, NT_DOUBLE, "double",
{{PubSubOption::ExcludeSelf(true)}});
auto remoteTopic =
storage.NetworkAnnounce("foo", "double", wpi::json::object(), 0);
// local set
EXPECT_CALL(network, Publish(_, _, _, _, _, _));
EXPECT_CALL(network, SetValue(_, _));
storage.SetEntryValue(entry, Value::MakeDouble(1.0, 50));
EXPECT_THAT(storage.ReadQueueDouble(entry), IsEmpty());
// network set
storage.NetworkSetValue(remoteTopic, Value::MakeDouble(2.0, 60));
EXPECT_THAT(storage.ReadQueueDouble(entry),
ElementsAre(TSEq<TimestampedDouble>(2.0, 60)));
}
} // namespace nt