1212// ZettaScale Zenoh Team, <[email protected] >1313//
1414
15+ #include < chrono>
1516#include < thread>
1617
1718#include " zenoh.hxx"
@@ -118,7 +119,9 @@ void put_sub_fifo_channel(Talloc& alloc) {
118119
119120 std::this_thread::sleep_for (1s);
120121
121- auto subscriber = session2.declare_subscriber (ke, channels::FifoChannel (16 ));
122+ std::vector<Subscriber<channels::FifoChannel::HandlerType<Sample>>> subscribers;
123+ subscribers.push_back (session2.declare_subscriber (ke, channels::FifoChannel (16 )));
124+ subscribers.push_back (session2.declare_subscriber (ke, channels::FifoChannel (16 )));
122125
123126 std::this_thread::sleep_for (1s);
124127
@@ -127,24 +130,28 @@ void put_sub_fifo_channel(Talloc& alloc) {
127130
128131 std::this_thread::sleep_for (1s);
129132
130- auto res = subscriber.handler ().recv ();
131- assert (std::holds_alternative<Sample>(res));
132- assert (std::get<Sample>(res).get_keyexpr () == " zenoh/test" );
133- assert (std::get<Sample>(res).get_payload ().as_string () == " first" );
134- res = subscriber.handler ().try_recv ();
135- assert (std::holds_alternative<Sample>(res));
136- assert (std::get<Sample>(res).get_keyexpr () == " zenoh/test" );
137- assert (std::get<Sample>(res).get_payload ().as_string () == " second" );
138-
139- res = subscriber.handler ().try_recv ();
140- assert (std::holds_alternative<channels::RecvError>(res));
141- assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
133+ for (const auto & subscriber : subscribers) {
134+ auto res = subscriber.handler ().recv ();
135+ assert (std::holds_alternative<Sample>(res));
136+ assert (std::get<Sample>(res).get_keyexpr () == " zenoh/test" );
137+ assert (std::get<Sample>(res).get_payload ().as_string () == " first" );
138+ res = subscriber.handler ().try_recv ();
139+ assert (std::holds_alternative<Sample>(res));
140+ assert (std::get<Sample>(res).get_keyexpr () == " zenoh/test" );
141+ assert (std::get<Sample>(res).get_payload ().as_string () == " second" );
142+
143+ res = subscriber.handler ().try_recv ();
144+ assert (std::holds_alternative<channels::RecvError>(res));
145+ assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
146+ }
142147
143148 // / after session close subscriber handler should become disconnected
144149 session2.close ();
145- res = subscriber.handler ().recv ();
146- assert (std::holds_alternative<channels::RecvError>(res));
147- assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
150+ for (const auto & subscriber : subscribers) {
151+ auto res = subscriber.handler ().recv ();
152+ assert (std::holds_alternative<channels::RecvError>(res));
153+ assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
154+ }
148155}
149156
150157template <typename Talloc>
@@ -155,7 +162,9 @@ void put_sub_ring_channel(Talloc& alloc) {
155162
156163 std::this_thread::sleep_for (1s);
157164
158- auto subscriber = session2.declare_subscriber (ke, channels::RingChannel (1 ));
165+ std::vector<Subscriber<channels::RingChannel::HandlerType<Sample>>> subscribers;
166+ subscribers.push_back (session2.declare_subscriber (ke, channels::RingChannel (1 )));
167+ subscribers.push_back (session2.declare_subscriber (ke, channels::RingChannel (1 )));
159168
160169 std::this_thread::sleep_for (1s);
161170
@@ -164,20 +173,24 @@ void put_sub_ring_channel(Talloc& alloc) {
164173
165174 std::this_thread::sleep_for (1s);
166175
167- auto res = subscriber.handler ().recv ();
168- assert (std::holds_alternative<Sample>(res));
169- assert (std::get<Sample>(res).get_keyexpr () == " zenoh/test" );
170- assert (std::get<Sample>(res).get_payload ().as_string () == " second" );
176+ for (const auto & subscriber : subscribers) {
177+ auto res = subscriber.handler ().recv ();
178+ assert (std::holds_alternative<Sample>(res));
179+ assert (std::get<Sample>(res).get_keyexpr () == " zenoh/test" );
180+ assert (std::get<Sample>(res).get_payload ().as_string () == " second" );
171181
172- res = subscriber.handler ().try_recv ();
173- assert (std::holds_alternative<channels::RecvError>(res));
174- assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
182+ res = subscriber.handler ().try_recv ();
183+ assert (std::holds_alternative<channels::RecvError>(res));
184+ assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_NODATA);
185+ }
175186
176187 // / after session close subscriber handler should become disconnected
177188 session2.close ();
178- res = subscriber.handler ().recv ();
179- assert (std::holds_alternative<channels::RecvError>(res));
180- assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
189+ for (const auto & subscriber : subscribers) {
190+ auto res = subscriber.handler ().recv ();
191+ assert (std::holds_alternative<channels::RecvError>(res));
192+ assert (std::get<channels::RecvError>(res) == channels::RecvError::Z_DISCONNECTED);
193+ }
181194}
182195
183196template <typename Talloc, bool share_alloc = true >
0 commit comments