1 #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
2 #include <doctest/doctest.h>
3 
4 #include <so_5_extra/sync/pub.hpp>
5 
6 #include <so_5/all.hpp>
7 
8 #include <test/3rd_party/various_helpers/time_limited_execution.hpp>
9 
10 namespace sync_ns = so_5::extra::sync;
11 
12 using namespace std::chrono_literals;
13 
14 using ask_reply_t = sync_ns::request_reply_t<int, int>;
15 
16 class service_t final : public so_5::agent_t
17 	{
18 	public :
service_t(context_t ctx)19 		service_t( context_t ctx ) : so_5::agent_t{ std::move(ctx) }
20 			{
21 				so_subscribe_self().event( &service_t::on_request );
22 			}
23 
24 	private :
25 		void
on_request(typename ask_reply_t::request_mhood_t cmd)26 		on_request( typename ask_reply_t::request_mhood_t cmd )
27 			{
28 				cmd->make_reply( cmd->request() * 2 );
29 			}
30 	};
31 
32 TEST_CASE( "do not close of reply_ch" )
33 {
34 	int result{};
35 
__anond07d60b00102null36 	run_with_time_limit( [&] {
37 			so_5::launch( [&](so_5::environment_t & env) {
38 						auto svc = env.introduce_coop( [&](so_5::coop_t & coop) {
39 								return coop.make_agent<service_t>()->so_direct_mbox();
40 							} );
41 
42 						auto ch = create_mchain(env);
43 
44 						ask_reply_t::initiate_with_custom_reply_to(
45 								svc,
46 								ch,
47 								sync_ns::do_not_close_reply_chain,
48 								2 );
49 						ask_reply_t::initiate_with_custom_reply_to(
50 								svc,
51 								ch,
52 								sync_ns::do_not_close_reply_chain,
53 								8 );
54 
55 						so_5::receive( so_5::from(ch).handle_n(2),
56 								[&result]( typename ask_reply_t::reply_mhood_t cmd )
57 								{
58 									result += *cmd;
59 								} );
60 
61 						env.stop();
62 					} );
63 		},
64 		5 );
65 
66 	REQUIRE( result == 20 );
67 }
68 
69