Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,12 @@ class BasicLmControlImpl final : public ILmControl
callback_ = std::move(callback);
}

// Check for any pending events from before the handler was installed.
onActivationResult();
// Check for any pending events from before the handler was installed. Only possible once connected;
// until then the receive handler, installed on connection, takes care of the samples.
if (connectedProxy() != nullptr)
{
onActivationResult();
}

return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,36 @@ TEST_F(LmControlUT, RegisterEmptyCallbackRejected)
EXPECT_EQ(result.error(), ExecErrc::kInvalidArguments);
}

TEST_F(LmControlUT, CallbackRegisteredBeforeConnectionIsUsedOnceConnected)
{
RecordProperty(
"Description",
"Registering an activation callback before the service is discovered succeeds without reading samples, "
"and the callback receives activation results once connected.");

auto sut = MakeLmControl();

std::optional<RunTargetName> name{};
EXPECT_CALL(mock_, GetNewSamples(_)).Times(0);
ASSERT_TRUE(sut->register_run_target_activation_callback([&](RunTargetActivationSource, RunTargetName n) {
name = n;
})
.has_value());
::testing::Mock::VerifyAndClearExpectations(&mock_);

ConnectService();

EXPECT_CALL(mock_, GetNewSamples(_)).WillOnce(Invoke([](std::size_t) {
return score::Result<std::vector<ActivationResult>>{MakeSamples({"Running"})};
}));

ASSERT_TRUE(receive_handler_);
receive_handler_();

ASSERT_TRUE(name.has_value());
EXPECT_EQ(name.value(), "Running");
}

TEST_F(LmControlUT, ActivationResultInvokesRegisteredCallback)
{
RecordProperty(
Expand Down
Loading