[ntcore] Fix special topic multi-subscriber handling (#4740)

It now matches server behavior, where "" doesn't match special topics.

Also fixes duplicate notification that could occur in some cases.
This commit is contained in:
Peter Johnson
2022-11-29 21:58:57 -08:00
committed by GitHub
parent df70351107
commit aa6499e920
2 changed files with 59 additions and 17 deletions

View File

@@ -789,6 +789,34 @@ TEST_F(LocalStorageNumberVariantsTest, ReadQueue) {
}
}
TEST_F(LocalStorageTest, MultiSubSpecial) {
EXPECT_CALL(network, Subscribe(_, _, _)).Times(2);
EXPECT_CALL(network, Publish(_, _, _, _, _, _)).Times(2);
EXPECT_CALL(network, SetValue(_, _)).Times(2);
EXPECT_CALL(listenerStorage, Activate(_, _, _)).Times(2);
auto subnormal = storage.SubscribeMultiple({{""}}, {});
auto subspecial = storage.SubscribeMultiple({{"", "$"}}, {});
auto pubnormal = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
auto specialTopic = storage.GetTopic("$topic");
auto pubspecial = storage.Publish(specialTopic, NT_DOUBLE, "double", {}, {});
storage.AddListener(1, subnormal, NT_EVENT_VALUE_ALL);
storage.AddListener(2, subspecial, NT_EVENT_VALUE_ALL);
EXPECT_CALL(
listenerStorage,
Notify(wpi::SpanEq(std::span<const NT_Listener>{{2}}), _, _, _, _));
storage.SetEntryValue(pubspecial, Value::MakeDouble(1.0, 30));
EXPECT_CALL(
listenerStorage,
Notify(wpi::SpanEq(std::span<const NT_Listener>{{1}}), _, _, _, _));
EXPECT_CALL(
listenerStorage,
Notify(wpi::SpanEq(std::span<const NT_Listener>{{2}}), _, _, _, _));
storage.SetEntryValue(pubnormal, Value::MakeDouble(2.0, 40));
}
TEST_F(LocalStorageTest, NetworkDuplicateDetect) {
EXPECT_CALL(network, Publish(_, _, _, _, _, _));
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});