Skip to content

Commit

Permalink
Fix qa_Messages on Emscripten build
Browse files Browse the repository at this point in the history
Issue here is that on WASM we have offsets added to our
Context.time which then get's out of sync to what the
client sent.

Signed-off-by: Daniel Nicoletti <[email protected]>
  • Loading branch information
dantti authored and RalphSteinhagen committed Nov 25, 2024
1 parent 648c977 commit 5f5b949
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/include/gnuradio-4.0/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,8 @@ class Block : public lifecycle::StateMachine<Derived> {
assert(propertyName == block::property::kActiveContext);

if (message.cmd == Get) {
message.data = {{"context", settings().activeContext().context}};
const auto& ctx = settings().activeContext();
message.data = {{"context", ctx.context}, {"time", ctx.time}};
return message;
}

Expand Down
14 changes: 9 additions & 5 deletions core/test/qa_Messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,6 @@ const boost::ut::suite MessagesTests = [] {
};

"get all contexts - w/o explicit serviceName"_test = [&] {
expect(eq(unitTestBlock.settings().getStoredAll().size(), 3UZ));

sendMessage<Get>(toBlock, "" /* serviceName */, block::property::kSettingsContexts /* endpoint */, {} /* data */);
expect(nothrow([&] { unitTestBlock.processScheduledMessages(); })) << "manually execute processing of messages";

Expand All @@ -492,18 +490,24 @@ const boost::ut::suite MessagesTests = [] {
expect(eq(reply.endpoint, std::string(block::property::kSettingsContexts)));
expect(reply.data.has_value());
expect(reply.data.value().contains("contexts"));
expect(reply.data.value().contains("times"));
auto contexts = std::get<std::vector<std::string>>(reply.data.value().at("contexts"));
auto times = std::get<std::vector<std::uint64_t>>(reply.data.value().at("times"));
expect(eq(contexts.size(), 3UZ));
expect(eq(times.size(), 3UZ));
expect(eq(contexts, std::vector<std::string>{"", "new_context", "test_context"}));
// We do not check the default context as it's time is now()
expect(eq(times[1], 2UZ));
expect(eq(times[2], 1UZ));
expect(eq(times[1], allStored.at("new_context")[0].first.time)); // We need internal time since wasm change our time
expect(eq(times[2], allStored.at("test_context")[0].first.time));
};

"remove new_context - w/o explicit serviceName"_test = [&] {
sendMessage<Disconnect>(toBlock, "" /* serviceName */, block::property::kSettingsCtx /* endpoint */, {{"context", "new_context"}, {"time", 2UZ}} /* data */);
// We need internal time since wasm change our time
const std::map<pmtv::pmt, std::vector<std::pair<SettingsCtx, property_map>>, settings::PMTCompare> allStored = unitTestBlock.settings().getStoredAll();
expect(eq(allStored.size(), 3UZ));
const std::uint64_t internalTimeForWasm = allStored.at("new_context")[0].first.time;

sendMessage<Disconnect>(toBlock, "" /* serviceName */, block::property::kSettingsCtx /* endpoint */, {{"context", "new_context"}, {"time", internalTimeForWasm}} /* data */);
expect(nothrow([&] { unitTestBlock.processScheduledMessages(); })) << "manually execute processing of messages";

expect(eq(fromBlock.streamReader().available(), 0UZ)) << "should not receive a reply";
Expand Down

0 comments on commit 5f5b949

Please sign in to comment.