Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CMurtagh-LGTM committed Dec 15, 2024
1 parent 016dce3 commit 2dba179
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/dsl/word/emit/Initialise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace dsl {
auto emitter = std::make_unique<threading::ReactionTask>(
nullptr,
false,
[](threading::ReactionTask& /*task*/) { return 1000; },
[](threading::ReactionTask& /*task*/) { return NUClear::util::Priority::HIGHEST; },
[](threading::ReactionTask& /*task*/) { return util::Inline::NEVER; },
[](threading::ReactionTask& /*task*/) { return Pool<>::descriptor(); },
[](threading::ReactionTask& /*task*/) {
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/api/ReactionHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class TestReactor : public test_util::TestBase<TestReactor> {
TestReactor(std::unique_ptr<NUClear::Environment> environment) : TestBase(std::move(environment)) {

// Make an always disabled reaction
a = on<Trigger<Message>, Priority::HIGH>().then([this](const Message& msg) { //
a = on<Trigger<Message>, Priority<NUClear::util::Priority::HIGH>>().then([this](const Message& msg) { //
events.push_back("Executed disabled reaction " + std::to_string(msg.i));
});
a.disable();

// Make a reaction that we toggle on and off
b = on<Trigger<Message>, Priority::HIGH>().then([this](const Message& msg) { //
b = on<Trigger<Message>, Priority<NUClear::util::Priority::HIGH>>().then([this](const Message& msg) { //
events.push_back("Executed toggled reaction " + std::to_string(msg.i));
b.disable();
emit(std::make_unique<Message>(1));
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/api/ReactionStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class TestReactor : public test_util::TestBase<TestReactor> {

// This reaction is here to emit something from a ReactionStatistics trigger
// This shouldn't cause reaction statistics of their own otherwise everything would explode
on<Trigger<ReactionEvent>, Priority::HIGH>().then("Loop Statistics", [this](const ReactionEvent&) { //
on<Trigger<ReactionEvent>, Priority<NUClear::util::Priority::HIGH>>().then("Loop Statistics", [this](const ReactionEvent&) { //
emit(std::make_unique<LoopMessage>());
});
on<Trigger<LoopMessage>>().then("No Statistics", [] {});


on<Trigger<ReactionEvent>, Priority::HIGH>().then("Reaction Stats Handler", [this](const ReactionEvent& event) {
on<Trigger<ReactionEvent>, Priority<NUClear::util::Priority::HIGH>>().then("Reaction Stats Handler", [this](const ReactionEvent& event) {
const auto& stats = *event.statistics;

// Other reactions statistics run on this because of built in NUClear reactors (e.g. chrono controller etc)
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/api/ReactionStatisticsTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
TestReactor(std::unique_ptr<NUClear::Environment> environment)
: TestBase(std::move(environment), true, std::chrono::seconds(2)) {

on<Trigger<Step<1>>, Priority::LOW>().then(initial_name + ":" + heavy_name, [this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then(initial_name + ":" + heavy_name, [this] {
code_events.emplace_back("Started " + initial_name + ":" + heavy_name, NUClear::clock::now());
code_events.emplace_back("Created " + heavy_name, NUClear::clock::now());
emit(std::make_unique<HeavyTask>());
Expand All @@ -74,7 +74,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
code_events.emplace_back("Finished " + heavy_name, NUClear::clock::now());
});

on<Trigger<Step<1>>, Priority::LOW>().then(initial_name + ":" + light_name, [this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then(initial_name + ":" + light_name, [this] {
code_events.emplace_back("Started " + initial_name + ":" + light_name, NUClear::clock::now());
code_events.emplace_back("Created " + light_name, NUClear::clock::now());
emit(std::make_unique<LightTask>());
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/dsl/BlockNoData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("MessageB with MessageA triggered");
});

on<Trigger<Step<1>>, Priority::LOW>().then([this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting MessageA");
emit(std::make_unique<MessageA>());
});
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/dsl/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,29 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("Buffer<4> reaction " + std::to_string(msg.i));
});

on<Trigger<Step<1>>, Priority::LOW>().then([this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Step 1");
emit(std::make_unique<Message>(1));
});
on<Trigger<Step<2>>, Priority::LOW>().then([this] {
on<Trigger<Step<2>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Step 2");
emit(std::make_unique<Message>(2));
emit(std::make_unique<Message>(3));
});
on<Trigger<Step<3>>, Priority::LOW>().then([this] {
on<Trigger<Step<3>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Step 3");
emit(std::make_unique<Message>(4));
emit(std::make_unique<Message>(5));
emit(std::make_unique<Message>(6));
});
on<Trigger<Step<4>>, Priority::LOW>().then([this] {
on<Trigger<Step<4>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Step 4");
emit(std::make_unique<Message>(7));
emit(std::make_unique<Message>(8));
emit(std::make_unique<Message>(9));
emit(std::make_unique<Message>(10));
});
on<Trigger<Step<5>>, Priority::LOW>().then([this] {
on<Trigger<Step<5>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Step 5");
emit(std::make_unique<Message>(11));
emit(std::make_unique<Message>(12));
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/dsl/DSLOrdering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("Empty function");
});

on<Trigger<Step<1>>, Priority::LOW>().then([this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting 1");
emit(std::make_unique<Message<1>>("1"));
});
on<Trigger<Step<2>>, Priority::LOW>().then([this] {
on<Trigger<Step<2>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting 2");
emit(std::make_unique<Message<2>>("2"));
});
on<Trigger<Step<3>>, Priority::LOW>().then([this] {
on<Trigger<Step<3>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting 3");
emit(std::make_unique<Message<3>>("3"));
});
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/dsl/FlagMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("MessageA with MessageB triggered");
});

on<Trigger<Step<1>>, Priority::LOW>().then([this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Step<1> triggered");
events.push_back("Emitting MessageA");
emit(std::make_unique<MessageA>());
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/dsl/IdleGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
});

// At low priority shutdown, this will run after all the global idles (should be 1) have been fired
on<Trigger<Step<2>>, Priority::LOW>().then([this] { powerplant.shutdown(); });
on<Trigger<Step<2>>, Priority<NUClear::util::Priority::LOW>>().then([this] { powerplant.shutdown(); });

// This shutdown is here in case the test times out so all the spinlocks don't hang the test
on<Shutdown, Pool<NonIdlePool>>().then([this] {
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/dsl/IdleSingle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
// Run this at low priority but have it first
// This way MainThread will get notified that it has access to Sync but then it will lose it when
// The other task on the default pool gets created so it'll be notified but unable to act
on<Trigger<TaskB>, MainThread, Priority::LOW, Sync<TestReactor>>().then([this](const TaskB& t) {
on<Trigger<TaskB>, MainThread, Priority<NUClear::util::Priority::LOW>, Sync<TestReactor>>().then([this](const TaskB& t) {
main_calls[t.i].fetch_add(1, std::memory_order_relaxed);

if (t.i + 1 < n_loops) {
Expand All @@ -87,7 +87,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
}
});
// This is the high priority task that preempts the main thread and makes it go idle again
on<Trigger<TaskB>, Pool<>, Priority::HIGH, Sync<TestReactor>>().then([this](const TaskB& t) { //
on<Trigger<TaskB>, Pool<>, Priority<NUClear::util::Priority::HIGH>, Sync<TestReactor>>().then([this](const TaskB& t) { //
default_calls[t.i].fetch_add(1, std::memory_order_relaxed);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/dsl/Once.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestReactor : public NUClear::Reactor {
TestReactor(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) {

// Make this priority high so it will always run first if it is able
on<Trigger<SimpleMessage>, Priority::HIGH, Once>().then([this](const SimpleMessage& msg) { //
on<Trigger<SimpleMessage>, Priority<NUClear::util::Priority::HIGH>, Once>().then([this](const SimpleMessage& msg) { //
events.push_back("Once Trigger executed " + std::to_string(msg.run));
});

Expand Down
44 changes: 22 additions & 22 deletions tests/tests/dsl/Priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,42 @@ class TestReactor : public test_util::TestBase<TestReactor> {
TestReactor(std::unique_ptr<NUClear::Environment> environment) : TestBase(std::move(environment)) {

// Declare in the order you'd expect them to fire
on<Trigger<Message<1>>, Priority::REALTIME>().then([this] { events.push_back("Realtime Message<1>"); });
on<Trigger<Message<1>>, Priority::HIGH>().then("High", [this] { events.push_back("High Message<1>"); });
on<Trigger<Message<1>>, Priority<NUClear::util::Priority::HIGHEST>>().then([this] { events.push_back("Highest Message<1>"); });
on<Trigger<Message<1>>, Priority<NUClear::util::Priority::HIGH>>().then("High", [this] { events.push_back("High Message<1>"); });
on<Trigger<Message<1>>>().then([this] { events.push_back("Default Message<1>"); });
on<Trigger<Message<1>>, Priority::NORMAL>().then("Normal", [this] { events.push_back("Normal Message<1>"); });
on<Trigger<Message<1>>, Priority::LOW>().then("Low", [this] { events.push_back("Low Message<1>"); });
on<Trigger<Message<1>>, Priority::IDLE>().then([this] { events.push_back("Idle Message<1>"); });
on<Trigger<Message<1>>, Priority<NUClear::util::Priority::NORMAL>>().then("Normal", [this] { events.push_back("Normal Message<1>"); });
on<Trigger<Message<1>>, Priority<NUClear::util::Priority::LOW>>().then("Low", [this] { events.push_back("Low Message<1>"); });
on<Trigger<Message<1>>, Priority<NUClear::util::Priority::LOWEST>>().then([this] { events.push_back("Lowest Message<1>"); });

// Declare in the opposite order to what you'd expect them to fire
on<Trigger<Message<2>>, Priority::IDLE>().then([this] { events.push_back("Idle Message<2>"); });
on<Trigger<Message<2>>, Priority::LOW>().then([this] { events.push_back("Low Message<2>"); });
on<Trigger<Message<2>>, Priority::NORMAL>().then([this] { events.push_back("Normal Message<2>"); });
on<Trigger<Message<2>>, Priority<NUClear::util::Priority::LOWEST>>().then([this] { events.push_back("Lowest Message<2>"); });
on<Trigger<Message<2>>, Priority<NUClear::util::Priority::LOW>>().then([this] { events.push_back("Low Message<2>"); });
on<Trigger<Message<2>>, Priority<NUClear::util::Priority::NORMAL>>().then([this] { events.push_back("Normal Message<2>"); });
on<Trigger<Message<2>>>().then([this] { events.push_back("Default Message<2>"); });
on<Trigger<Message<2>>, Priority::HIGH>().then([this] { events.push_back("High Message<2>"); });
on<Trigger<Message<2>>, Priority::REALTIME>().then([this] { events.push_back("Realtime Message<2>"); });
on<Trigger<Message<2>>, Priority<NUClear::util::Priority::HIGH>>().then([this] { events.push_back("High Message<2>"); });
on<Trigger<Message<2>>, Priority<NUClear::util::Priority::HIGHEST>>().then([this] { events.push_back("Highest Message<2>"); });

// Declare in a random order
std::array<int, 5> order = {0, 1, 2, 3, 4};
std::shuffle(order.begin(), order.end(), std::mt19937(std::random_device()()));
for (const auto& i : order) {
switch (i) {
case 0:
on<Trigger<Message<3>>, Priority::REALTIME>().then(
[this] { events.push_back("Realtime Message<3>"); });
on<Trigger<Message<3>>, Priority<NUClear::util::Priority::HIGHEST>>().then(
[this] { events.push_back("Highest Message<3>"); });
break;
case 1:
on<Trigger<Message<3>>, Priority::HIGH>().then([this] { events.push_back("High Message<3>"); });
on<Trigger<Message<3>>, Priority<NUClear::util::Priority::HIGH>>().then([this] { events.push_back("High Message<3>"); });
break;
case 2:
on<Trigger<Message<3>>, Priority::NORMAL>().then([this] { events.push_back("Normal Message<3>"); });
on<Trigger<Message<3>>, Priority<NUClear::util::Priority::NORMAL>>().then([this] { events.push_back("Normal Message<3>"); });
on<Trigger<Message<3>>>().then([this] { events.push_back("Default Message<3>"); });
break;
case 3:
on<Trigger<Message<3>>, Priority::LOW>().then([this] { events.push_back("Low Message<3>"); });
on<Trigger<Message<3>>, Priority<NUClear::util::Priority::LOW>>().then([this] { events.push_back("Low Message<3>"); });
break;
case 4:
on<Trigger<Message<3>>, Priority::IDLE>().then([this] { events.push_back("Idle Message<3>"); });
on<Trigger<Message<3>>, Priority<NUClear::util::Priority::LOWEST>>().then([this] { events.push_back("Lowest Message<3>"); });
break;
default: throw std::invalid_argument("Should be impossible");
}
Expand Down Expand Up @@ -98,9 +98,9 @@ TEST_CASE("Tests that priority orders the tasks appropriately", "[api][priority]
plant.start();

const std::vector<std::string> expected = {
"Realtime Message<1>",
"Realtime Message<2>",
"Realtime Message<3>",
"Highest Message<1>",
"Highest Message<2>",
"Highest Message<3>",
"High Message<1>",
"High Message<2>",
"High Message<3>",
Expand All @@ -113,9 +113,9 @@ TEST_CASE("Tests that priority orders the tasks appropriately", "[api][priority]
"Low Message<1>",
"Low Message<2>",
"Low Message<3>",
"Idle Message<1>",
"Idle Message<2>",
"Idle Message<3>",
"Lowest Message<1>",
"Lowest Message<2>",
"Lowest Message<3>",
};

// Make an info print the diff in an easy to read way if we fail
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/dsl/RawFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ class TestReactor : public test_util::TestBase<TestReactor> {
on<Trigger<Message>, Trigger<Data>>().then(raw_function_test_right_arg);
on<Trigger<Message>, Trigger<Data>>().then(raw_function_test_both_args);

on<Trigger<Step<1>>, Priority::LOW>().then([this] { emit(std::make_unique<Data>("D1")); });
on<Trigger<Step<2>>, Priority::LOW>().then([this] { emit(std::make_unique<Message>("M2")); });
on<Trigger<Step<3>>, Priority::LOW>().then([this] { emit(std::make_unique<Data>("D3")); });
on<Trigger<Step<4>>, Priority::LOW>().then([this] { emit(std::make_unique<Message>("M4")); });
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then([this] { emit(std::make_unique<Data>("D1")); });
on<Trigger<Step<2>>, Priority<NUClear::util::Priority::LOW>>().then([this] { emit(std::make_unique<Message>("M2")); });
on<Trigger<Step<3>>, Priority<NUClear::util::Priority::LOW>>().then([this] { emit(std::make_unique<Data>("D3")); });
on<Trigger<Step<4>>, Priority<NUClear::util::Priority::LOW>>().then([this] { emit(std::make_unique<Message>("M4")); });

on<Startup>().then([this] {
emit(std::make_unique<Step<1>>());
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/dsl/Shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("Shutdown task executed");
});

on<Trigger<Step<1>>, Priority::LOW>().then([this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Requesting shutdown");
powerplant.shutdown();
});
Expand Down
18 changes: 9 additions & 9 deletions tests/tests/dsl/Transient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,39 +72,39 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back(m.msg + " : " + t.msg);
});

on<Trigger<Step<1>>, Priority::LOW>().then([this] {
on<Trigger<Step<1>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Message 1");
emit(std::make_unique<Message>("S1"));
});
on<Trigger<Step<2>>, Priority::LOW>().then([this] {
on<Trigger<Step<2>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Transient 1");
emit(std::make_unique<TransientMessage>("T1", true));
});
on<Trigger<Step<3>>, Priority::LOW>().then([this] {
on<Trigger<Step<3>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Message 2");
emit(std::make_unique<Message>("S2"));
});
on<Trigger<Step<4>>, Priority::LOW>().then([this] {
on<Trigger<Step<4>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Invalid Transient 2");
emit(std::make_unique<TransientMessage>("T2", false));
});
on<Trigger<Step<5>>, Priority::LOW>().then([this] {
on<Trigger<Step<5>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Message 3");
emit(std::make_unique<Message>("S3"));
});
on<Trigger<Step<6>>, Priority::LOW>().then([this] {
on<Trigger<Step<6>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Transient 3");
emit(std::make_unique<TransientMessage>("T3", true));
});
on<Trigger<Step<7>>, Priority::LOW>().then([this] {
on<Trigger<Step<7>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Transient 4");
emit(std::make_unique<TransientMessage>("T4", true));
});
on<Trigger<Step<8>>, Priority::LOW>().then([this] {
on<Trigger<Step<8>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Invalid Transient 5");
emit(std::make_unique<TransientMessage>("T5", false));
});
on<Trigger<Step<9>>, Priority::LOW>().then([this] {
on<Trigger<Step<9>>, Priority<NUClear::util::Priority::LOW>>().then([this] {
events.push_back("Emitting Message 4");
emit(std::make_unique<Message>("S4"));
});
Expand Down
Loading

0 comments on commit 2dba179

Please sign in to comment.