-
Notifications
You must be signed in to change notification settings - Fork 182
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
[core] add/improved IsPublished/IsSubscribed logic (master) #1633
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||||||
|
@@ -216,3 +216,97 @@ TEST(core_cpp_pubsub, SporadicEmptyReceives) | |||||
// finalize eCAL API | ||||||
EXPECT_EQ(0, eCAL::Finalize()); | ||||||
} | ||||||
|
||||||
TEST(PubSub, TestSubscriberSeen) | ||||||
{ | ||||||
// initialize eCAL API | ||||||
EXPECT_EQ(0, eCAL::Initialize(0, nullptr, "subscriber_seen")); | ||||||
|
||||||
// enable data loopback | ||||||
eCAL::Util::EnableLoopback(true); | ||||||
|
||||||
std::atomic<bool> subscriber_seen_at_publication_start(false); | ||||||
std::atomic<bool> subscriber_seen_at_publication_end(false); | ||||||
|
||||||
std::atomic<bool> do_start_publication(false); | ||||||
std::atomic<bool> publication_finished(false); | ||||||
|
||||||
// publishing thread | ||||||
auto publisher_thread = [&]() { | ||||||
eCAL::Publisher::Configuration pub_config; | ||||||
pub_config.shm.acknowledge_timeout_ms = 500; | ||||||
eCAL::CPublisher pub("blob", pub_config); | ||||||
|
||||||
int cnt(0); | ||||||
const auto max_runs(1000); | ||||||
while (eCAL::Ok()) | ||||||
{ | ||||||
if (do_start_publication && cnt < max_runs) | ||||||
{ | ||||||
if (cnt == 0) | ||||||
{ | ||||||
subscriber_seen_at_publication_start = pub.IsSubscribed(); | ||||||
} | ||||||
|
||||||
pub.Send(std::to_string(cnt)); | ||||||
cnt++; | ||||||
|
||||||
if (cnt == max_runs) | ||||||
{ | ||||||
subscriber_seen_at_publication_end = pub.IsSubscribed(); | ||||||
publication_finished = true; | ||||||
break; | ||||||
} | ||||||
} | ||||||
} | ||||||
}; | ||||||
|
||||||
// subscribing thread | ||||||
auto subscriber_thread = [&]() { | ||||||
eCAL::CSubscriber sub("blob"); | ||||||
bool received(false); | ||||||
auto max_lines(10); | ||||||
auto receive_lambda = [&received, &max_lines](const char* /*topic_name_*/, const struct eCAL::SReceiveCallbackData* data_) | ||||||
{ | ||||||
if (max_lines) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: implicit conversion 'int' -> bool [readability-implicit-bool-conversion]
Suggested change
|
||||||
{ | ||||||
// the final log should look like this | ||||||
// ----------------------------------- | ||||||
// Receiving 0 | ||||||
// Receiving 1 | ||||||
// Receiving 2 | ||||||
// Receiving 3 | ||||||
// Receiving 4 | ||||||
// Receiving 5 | ||||||
// Receiving 6 | ||||||
// Receiving 7 | ||||||
// Receiving 8 | ||||||
// Receiving 9 | ||||||
// ----------------------------------- | ||||||
std::cout << "Receiving " << std::string(static_cast<const char*>(data_->buf), data_->size) << std::endl; | ||||||
max_lines--; | ||||||
} | ||||||
}; | ||||||
sub.AddReceiveCallback(receive_lambda); | ||||||
|
||||||
while (eCAL::Ok() && !publication_finished) | ||||||
{ | ||||||
if (sub.IsPublished()) do_start_publication = true; | ||||||
} | ||||||
}; | ||||||
|
||||||
// create threads for publisher and subscriber | ||||||
std::thread pub_thread(publisher_thread); | ||||||
std::thread sub_thread(subscriber_thread); | ||||||
|
||||||
// join threads to the main thread | ||||||
pub_thread.join(); | ||||||
sub_thread.join(); | ||||||
|
||||||
// finalize eCAL API | ||||||
eCAL::Finalize(); | ||||||
|
||||||
// check if the publisher has seen the subscriber | ||||||
EXPECT_TRUE(subscriber_seen_at_publication_start); | ||||||
EXPECT_TRUE(subscriber_seen_at_publication_end); | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: all parameters should be named in a function [readability-named-parameter]