2323#include < booster/log.h>
2424#include " test.h"
2525
26+ int g_fail;
27+ #define TESTNT (x ) do { if (x) break ; std::cerr << " FAIL: " #x " in line: " << __LINE__ << std::endl; g_fail = 1 ; return ; } while (0 )
28+
2629booster::thread_specific_ptr<int > g_thread_id;
2730booster::mutex g_id_lock;
2831int g_thread_id_counter=1000 ;
@@ -195,6 +198,76 @@ struct marker {
195198 std::string name_;
196199};
197200
201+ struct pools {
202+ booster::weak_ptr<cppcms::application_specific_pool> sync,async;
203+ bool async_requested;
204+ pools () : async_requested(false ) {}
205+ };
206+
207+ class sender : public cppcms ::application {
208+ public:
209+
210+ struct src_prop {
211+ bool src_async;
212+ bool src_created;
213+ bool src_to_app;
214+ };
215+ sender (cppcms::service &srv,pools *p) :
216+ cppcms::application (srv),
217+ pools_ (p),
218+ first_time_ (true )
219+ {
220+ }
221+
222+ void main (std::string url)
223+ {
224+ if (url!=" /sender" ) {
225+ src_prop *p = context ().get_specific <src_prop>();
226+ TESTNT (p);
227+ response ().out () << " async=" << is_asynchronous () << " \n "
228+ " src_async=" << p->src_async <<" \n "
229+ " src_created=" << p->src_created <<" \n "
230+ " src_to_app=" << p->src_to_app <<" \n "
231+ " path=" << url<<" \n "
232+ ;
233+ return ;
234+ }
235+
236+ src_prop *p=new src_prop ();
237+ context ().reset_specific <src_prop>(p);
238+
239+ bool to_app = request ().get (" to_app" )==" 1" ;
240+ p->src_to_app = to_app;
241+ p->src_async = is_asynchronous ();
242+ p->src_created = false ;
243+ booster::shared_ptr<cppcms::application_specific_pool> tgt;
244+ if (request ().get (" to" )==" sync" )
245+ tgt = pools_->sync .lock ();
246+ else
247+ tgt = pools_->async .lock ();
248+
249+ booster::shared_ptr<cppcms::http::context> ctx = release_context ();
250+ TESTNT (tgt);
251+
252+ if (!to_app) {
253+ ctx->submit_to_pool (tgt," /pool" );
254+ return ;
255+ }
256+
257+ booster::intrusive_ptr<cppcms::application> app;
258+ app =tgt->asynchronous_application_by_io_service (service ().get_io_service ());
259+ if (!app) {
260+ app = tgt->asynchronous_application_by_io_service (service ().get_io_service (),service ());
261+ p->src_created =true ;
262+ }
263+ TESTNT (app);
264+ ctx->submit_to_asynchronous_application (app," /app" );
265+ }
266+ private:
267+ pools *pools_;
268+ bool first_time_;
269+ };
270+
198271int main (int argc,char **argv)
199272{
200273 try {
@@ -247,6 +320,25 @@ int main(int argc,char **argv)
247320
248321 srv.applications_pool ().mount (cppcms::create_pool<tester>(),mount_point (" /test" ),cppcms::app::asynchronous);
249322
323+ pools p;
324+ {
325+ booster::shared_ptr<cppcms::application_specific_pool> tmp;
326+ srv.applications_pool ().mount (
327+ (tmp=cppcms::create_pool<sender>(&p)),
328+ mount_point (" /async" ," /sender" ,0 ),
329+ cppcms::app::asynchronous);
330+ p.async = tmp;
331+ }
332+
333+ {
334+ booster::shared_ptr<cppcms::application_specific_pool> tmp;
335+ srv.applications_pool ().mount (
336+ (tmp=cppcms::create_pool<sender>(&p)),
337+ mount_point (" /sync" ," /sender" ,0 ),
338+ cppcms::app::synchronous);
339+ p.sync = tmp;
340+ }
341+
250342 srv.after_fork (thread_submitter (srv));
251343 srv.run ();
252344
@@ -267,9 +359,12 @@ int main(int argc,char **argv)
267359 std::cerr << e.what () << std::endl;
268360 return EXIT_FAILURE;
269361 }
270- if (run_ok)
271- std::cout << " Ok" << std::endl;
272- else
362+ if (run_ok && !g_fail) {
363+ std::cout << " Full Test: Ok" << std::endl;
364+ return EXIT_SUCCESS;
365+ }
366+ else {
273367 std::cout << " FAILED" << std::endl;
274- return run_ok ? EXIT_SUCCESS : EXIT_FAILURE;
368+ return EXIT_FAILURE;
369+ }
275370}
0 commit comments