Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #468 #470

Merged
merged 3 commits into from
Feb 2, 2024
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
7 changes: 7 additions & 0 deletions include/gz/transport/Discovery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ namespace gz
/// (e.g. if the discovery has not been started).
public: bool Advertise(const Pub &_publisher)
{
DiscoveryCallback<Pub> cb;

{
std::lock_guard<std::mutex> lock(this->mutex);

Expand All @@ -315,8 +317,13 @@ namespace gz
// Add the addressing information (local publisher).
if (!this->info.AddPublisher(_publisher))
return false;

cb = this->connectionCb;
}

if (cb)
cb(_publisher);

// Only advertise a message outside this process if the scope
// is not 'Process'
if (_publisher.Options().Scope() != Scope_t::PROCESS)
Expand Down
25 changes: 25 additions & 0 deletions src/Node_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,23 @@ class MyTestClass
EXPECT_FALSE(this->callbackSrvExecuted);
}

/// \brief Advertise and request a service without waiting for response.
public: void TestServiceCallRequestingBeforeAdvertising()
{
msgs::Int32 req;
req.set_data(data);

this->Reset();

// Request a valid service using a member function callback.
this->node.Request(g_topic, req, &MyTestClass::EchoResponse, this);

// Advertise and request a valid service.
EXPECT_TRUE(this->node.Advertise(g_topic, &MyTestClass::Echo, this));
std::this_thread::sleep_for(std::chrono::milliseconds(300));
EXPECT_TRUE(this->responseExecuted);
}

public: void Reset()
{
this->callbackExecuted = false;
Expand Down Expand Up @@ -1154,6 +1171,14 @@ TEST(NodeTest, ClassMemberCallbackServiceWithoutInput)
client.TestServiceCallWithoutInput();
}

//////////////////////////////////////////////////
/// \brief Make an asynchronous service call, and then, advertise the service.
TEST(NodeTest, ClassMemberRequestServiceBeforeAdvertise)
{
MyTestClass client;
client.TestServiceCallRequestingBeforeAdvertising();
}

//////////////////////////////////////////////////
/// \brief Check that the types advertised and published match.
TEST(NodeTest, TypeMismatch)
Expand Down
Loading