Skip to content

Commit

Permalink
[core] Protobuf Publisher Send should return the actual send size. (#…
Browse files Browse the repository at this point in the history
…1681) (#1685)

Co-authored-by: KerstinKeller <[email protected]>
  • Loading branch information
eclipse-ecal-bot and KerstinKeller authored Aug 21, 2024
1 parent 72a8b5c commit 6f880f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 2 additions & 3 deletions ecal/core/include/ecal/msg/protobuf/publisher.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -167,8 +167,7 @@ namespace eCAL
size_t Send(const T& msg_, long long time_, long long acknowledge_timeout_ms_)
{
CPayload payload{ msg_ };
eCAL::CPublisher::Send(payload, time_, acknowledge_timeout_ms_);
return(0);
return eCAL::CPublisher::Send(payload, time_, acknowledge_timeout_ms_);
}


Expand Down
23 changes: 17 additions & 6 deletions testing/ecal/pubsub_proto_test/src/proto_subscriber_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,12 +50,20 @@ class ProtoSubscriberTest : public ::testing::Test {
eCAL::Finalize();
}

void SendPerson(eCAL::protobuf::CPublisher<pb::People::Person>& pub)
size_t SendPerson(eCAL::protobuf::CPublisher<pb::People::Person>& pub)
{
pb::People::Person p;
p.set_id(1);
p.set_name("Max");
pub.Send(p);
return pub.Send(p);
}

size_t GetPersonSize()
{
#if GOOGLE_PROTOBUF_VERSION >= 3001000
return static_cast<size_t>(p.ByteSizeLong());
#else
return static_cast<size_t>(p.ByteSize());
#endif
}

void OnPerson(const char*, const pb::People::Person&, long long, long long)
Expand All @@ -64,6 +72,9 @@ class ProtoSubscriberTest : public ::testing::Test {
}

std::atomic<int> received_callbacks;

private:
pb::People::Person p;
};

TEST_F(ProtoSubscriberTest, SendReceive)
Expand All @@ -78,11 +89,11 @@ TEST_F(ProtoSubscriberTest, SendReceive)

std::this_thread::sleep_for(std::chrono::milliseconds(2000));

SendPerson(person_pub);
auto bytes_send = SendPerson(person_pub);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
// assert that the OnPerson callback has been called once.
ASSERT_EQ(1, received_callbacks);

ASSERT_EQ(bytes_send, GetPersonSize());
}


Expand Down

0 comments on commit 6f880f8

Please sign in to comment.