|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
How to test callbacks / non-blocking calls?Hello,
I am testing some sort of socket connection where I have async callbacks which are of course non-blocking calls. How can Boost::Test provide some testing facilities for that? Here is a very simple example: void mmyFunc(const char * text) { // compare } BOOST_AUTO_TEST_CASE(foo) { mocksocket m; MySocket my(1000); // listen on port 1000 my.callback(myFunc); // register callback m.send("foo"); BOOST_CHECK_?? // test case ended } So my test cannot be executed at once in the case since the callback most probably fires too late. What are workarrounds for such scenarios? Thank you Sam -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 _______________________________________________ Boost-Testing mailing list Boost-Testing@... http://lists.boost.org/mailman/listinfo.cgi/boost-testing |
|
|
Re: How to test callbacks / non-blocking calls? <ariasgore <at> gmx.de> writes:
> void mmyFunc(const char * text) > { > // compare > } > BOOST_AUTO_TEST_CASE(foo) > { > mocksocket m; > MySocket my(1000); // listen on port 1000 > my.callback(myFunc); // register callback > m.send("foo"); > > BOOST_CHECK_?? > // test case ended What exactly you want to check here? > } > > So my test cannot be executed at once in the case > since the callback most probably fires too late. What are What do you mean by too late? after you exit from the case? > workarounds for such scenarios? Why don't you perform checks inside the callback? Gennadiy _______________________________________________ Boost-Testing mailing list Boost-Testing@... http://lists.boost.org/mailman/listinfo.cgi/boost-testing |
|
|
Re: How to test callbacks / non-blocking calls?Hello Gennadiy,
as far as I got the auto registering I thought that only doing the tests in BOOST_AUTO_TEST_CASE will be noticed by Boost::Test. In my scenario I am testing a socket communication, which is known to be async. If I do something like: void myFunc(const char * text) { BOOST_CHECK_STH_THAT_FAILED() } BOOST_AUTO_TEST_CASE(foo) { mocksocket m; MySocket my(1000); // listen on port 1000 my.callback(myFunc); // register callback // the myFunc callback will be called in lets say 20 seconds later, // socket delay or communication with a remote host that is far away. // even if mock objects would accelerate this part, it would still not // be in-sync with the Test-case body m.send("foo"); // test finished after 4 ms } Will that work anyhow? Since the boost_check is done in a method myFunc that is not directly executed in the BOOST_AUTO_TEST_CASE(foo) function scope. The BOOST_AUTO_TEST_CASE(foo) needs 4 ms to complete, whereas the socket communication takes up to 20 seconds to process. How can boost::test notice anything of myFunc if the test and the whole programm is already finished after 4 ms ? Thank you Sam -------- Original-Nachricht -------- > Datum: Thu, 18 Jun 2009 17:20:33 +0000 (UTC) > Von: Gennadiy Rozental <rogeeff@...> > An: boost-testing@... > Betreff: Re: [Boost-testing] How to test callbacks / non-blocking calls? > <ariasgore <at> gmx.de> writes: > > > void mmyFunc(const char * text) > > { > > // compare > > } > > BOOST_AUTO_TEST_CASE(foo) > > { > > mocksocket m; > > MySocket my(1000); // listen on port 1000 > > my.callback(myFunc); // register callback > > m.send("foo"); > > > > BOOST_CHECK_?? > > // test case ended > > What exactly you want to check here? > > > } > > > > So my test cannot be executed at once in the case > > since the callback most probably fires too late. What are > > What do you mean by too late? after you exit from the case? > > > workarounds for such scenarios? > > > Why don't you perform checks inside the callback? > > > Gennadiy > > _______________________________________________ > Boost-Testing mailing list > Boost-Testing@... > http://lists.boost.org/mailman/listinfo.cgi/boost-testing -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 _______________________________________________ Boost-Testing mailing list Boost-Testing@... http://lists.boost.org/mailman/listinfo.cgi/boost-testing |
|
|
Re: How to test callbacks / non-blocking calls? <ariasgore <at> gmx.de> writes:
> > Hello Gennadiy, > > as far as I got the auto registering I thought that only doing > the tests in BOOST_AUTO_TEST_CASE will be > noticed by Boost::Test. The check should occur while test case is being executed. That said it can be done in some callback which is being invoked. > void myFunc(const char * text) > { > BOOST_CHECK_STH_THAT_FAILED() > > } > BOOST_AUTO_TEST_CASE(foo) > { > mocksocket m; > MySocket my(1000); // listen on port 1000 > my.callback(myFunc); // register callback > > // the myFunc callback will be called in lets say 20 seconds later, > // socket delay or communication with a remote host that is far away. > // even if mock objects would accelerate this part, it would still not > // be in-sync with the Test-case body > m.send("foo"); > > // test finished after 4 ms > } > > Will that work anyhow? Since the boost_check is done in a method myFunc that > BOOST_AUTO_TEST_CASE(foo) function scope. The BOOST_AUTO_TEST_CASE(foo) needs 4 ms to complete, > whereas the socket communication takes up to 20 seconds to process. How can boost::test notice anything > of myFunc if the test and the whole programm is already finished after 4 ms ? Can't you wait till communication is completed? In worse case you can wait on conditional variable and trigger it inside the callback. Gennadiy _______________________________________________ Boost-Testing mailing list Boost-Testing@... http://lists.boost.org/mailman/listinfo.cgi/boost-testing |
|
|
Re: How to test callbacks / non-blocking calls?Hello,
> Can't you wait till communication is completed? In worse case you can wait > on > conditional variable and trigger it inside the callback. Is this a general aproach on such problems? I already had some thoughts about a while (!finish) sleep(x) loop but was not sure if there is a more cleaner way to do that, since this looks a lot like hacking around :) Best regards, Sam -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 _______________________________________________ Boost-Testing mailing list Boost-Testing@... http://lists.boost.org/mailman/listinfo.cgi/boost-testing |
|
|
Re: How to test callbacks / non-blocking calls?ariasgore@... wrote:
> Hello, > >> Can't you wait till communication is completed? In worse case you can wait >> on >> conditional variable and trigger it inside the callback. > > Is this a general approach on such problems? I already had some thoughts about a while (!finish) sleep(x) loop but was not sure if there is a more cleaner way to do that, since this looks a lot like hacking around :) You can choose whatever approach seems less hacky to you, but I can't check assertion 20 seconds after your test module is finished. Gennadiy _______________________________________________ Boost-Testing mailing list Boost-Testing@... http://lists.boost.org/mailman/listinfo.cgi/boost-testing |
| Free embeddable forum powered by Nabble | Forum Help |