mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[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:
@@ -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", {}, {});
|
||||
|
||||
Reference in New Issue
Block a user