Skip to content

Commit

Permalink
Merge branch 'main' into loaned-mut
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Feb 28, 2025
2 parents 2bd3b5e + 2962e51 commit e6584e7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
1 change: 1 addition & 0 deletions docs/pubsub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Subscriber example with non-blocking stream interface:
.. code-block:: c++

#include "zenoh.hxx"
#include <chrono>
#include <iostream>
#include <thread>

Expand Down
1 change: 1 addition & 0 deletions examples/universal/z_get_channel_non_blocking.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <stdio.h>
#include <string.h>

#include <chrono>
#include <condition_variable>
#include <iostream>
#include <thread>
Expand Down
1 change: 1 addition & 0 deletions tests/universal/network/liveliness.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#include <chrono>
#include <thread>
#include <unordered_set>

Expand Down
67 changes: 40 additions & 27 deletions tests/universal/network/pub_sub.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#include <chrono>
#include <thread>

#include "zenoh.hxx"
Expand Down Expand Up @@ -118,7 +119,9 @@ void put_sub_fifo_channel(Talloc& alloc) {

std::this_thread::sleep_for(1s);

auto subscriber = session2.declare_subscriber(ke, channels::FifoChannel(16));
std::vector<Subscriber<channels::FifoChannel::HandlerType<Sample>>> subscribers;
subscribers.push_back(session2.declare_subscriber(ke, channels::FifoChannel(16)));
subscribers.push_back(session2.declare_subscriber(ke, channels::FifoChannel(16)));

std::this_thread::sleep_for(1s);

Expand All @@ -127,24 +130,28 @@ void put_sub_fifo_channel(Talloc& alloc) {

std::this_thread::sleep_for(1s);

auto res = subscriber.handler().recv();
assert(std::holds_alternative<Sample>(res));
assert(std::get<Sample>(res).get_keyexpr() == "zenoh/test");
assert(std::get<Sample>(res).get_payload().as_string() == "first");
res = subscriber.handler().try_recv();
assert(std::holds_alternative<Sample>(res));
assert(std::get<Sample>(res).get_keyexpr() == "zenoh/test");
assert(std::get<Sample>(res).get_payload().as_string() == "second");

res = subscriber.handler().try_recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
for (const auto& subscriber : subscribers) {
auto res = subscriber.handler().recv();
assert(std::holds_alternative<Sample>(res));
assert(std::get<Sample>(res).get_keyexpr() == "zenoh/test");
assert(std::get<Sample>(res).get_payload().as_string() == "first");
res = subscriber.handler().try_recv();
assert(std::holds_alternative<Sample>(res));
assert(std::get<Sample>(res).get_keyexpr() == "zenoh/test");
assert(std::get<Sample>(res).get_payload().as_string() == "second");

res = subscriber.handler().try_recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
}

/// after session close subscriber handler should become disconnected
session2.close();
res = subscriber.handler().recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
for (const auto& subscriber : subscribers) {
auto res = subscriber.handler().recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
}
}

template <typename Talloc>
Expand All @@ -155,7 +162,9 @@ void put_sub_ring_channel(Talloc& alloc) {

std::this_thread::sleep_for(1s);

auto subscriber = session2.declare_subscriber(ke, channels::RingChannel(1));
std::vector<Subscriber<channels::RingChannel::HandlerType<Sample>>> subscribers;
subscribers.push_back(session2.declare_subscriber(ke, channels::RingChannel(1)));
subscribers.push_back(session2.declare_subscriber(ke, channels::RingChannel(1)));

std::this_thread::sleep_for(1s);

Expand All @@ -164,20 +173,24 @@ void put_sub_ring_channel(Talloc& alloc) {

std::this_thread::sleep_for(1s);

auto res = subscriber.handler().recv();
assert(std::holds_alternative<Sample>(res));
assert(std::get<Sample>(res).get_keyexpr() == "zenoh/test");
assert(std::get<Sample>(res).get_payload().as_string() == "second");
for (const auto& subscriber : subscribers) {
auto res = subscriber.handler().recv();
assert(std::holds_alternative<Sample>(res));
assert(std::get<Sample>(res).get_keyexpr() == "zenoh/test");
assert(std::get<Sample>(res).get_payload().as_string() == "second");

res = subscriber.handler().try_recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
res = subscriber.handler().try_recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
}

/// after session close subscriber handler should become disconnected
session2.close();
res = subscriber.handler().recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
for (const auto& subscriber : subscribers) {
auto res = subscriber.handler().recv();
assert(std::holds_alternative<channels::RecvError>(res));
assert(std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
}
}

template <typename Talloc, bool share_alloc = true>
Expand Down
1 change: 1 addition & 0 deletions tests/universal/network/queryable_get.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#include <chrono>
#include <thread>

#include "zenoh.hxx"
Expand Down
1 change: 1 addition & 0 deletions tests/zenohc/shm_api.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#include <chrono>
#include <thread>
#include <unordered_set>

Expand Down

0 comments on commit e6584e7

Please sign in to comment.