Testing and faking ASIO I/O objects

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Testing and faking ASIO I/O objects

Boost - Users mailing list
How is people around here testing code which uses ASIO?
I guess something like

GIVEN("SOMETHING THAT STARTS BY DOING A NAME RESOLVER IS STARTED")
    fakeResolver.async_resolve("www.google.com", "80",
HandlerCallingConnect); // This stores the completion handler (and an
executor_work_guard) internally

    WHEN("THE RESOLVER RETURNS WITHOUT ERROR")
        fakeResolver.completeWithFakeResult("1.2.3.4", error_code());
// This post() the completion handler with the arguments you give it
here
        io_context.poll();

        THEN("A CONNECTION IS ATTEMPTED")
            EXPECT_CALL(fakeSocket, async_connect());

would be nice. But the "stores the completion handler" part doesn't
look that simple. I have found some attempts online, but they seems to
store the completion handlers into a vector of std::function and post
them through std::bind, so possibly using the wrong executor, etc.
There is any good set of ASIO I/O object fakes available?
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Testing and faking ASIO I/O objects

Boost - Users mailing list
On Wed, Aug 29, 2018 at 2:03 PM Cristian Morales Vega via Boost-users
<[hidden email]> wrote:
> There is any good set of ASIO I/O object fakes available?

Beast experimental interfaces provide testing facilities which meet
the requirements of the following Asio concepts:

    SyncReadStream
    SyncWriteStream
    AsyncReadStream
    AsyncWriteStream

This is provided by the boost::beast::test::stream class, which works
with the test::fail_counter class to allow for automated failure
testing.

Docs:
<https://www.boost.org/doc/libs/1_68_0/libs/beast/doc/html/beast/ref/boost__beast__test__stream.html>
<https://www.boost.org/doc/libs/1_68_0/libs/beast/doc/html/beast/ref/boost__beast__test__fail_count.html>
<https://www.boost.org/doc/libs/1_68_0/libs/beast/doc/html/beast/ref/boost__beast__test__connect.html>
<https://www.boost.org/doc/libs/1_68_0/libs/beast/doc/html/beast/ref/boost__beast__test__error.html>

Includes:
<https://github.com/boostorg/beast/tree/develop/include/boost/beast/experimental/test>

The Beast unit tests make heavy use of the test::stream class. Example:
<https://github.com/boostorg/beast/blob/1da229a27c6f0539d422bcedbcf47cfe2517164a/test/beast/http/read.cpp#L258>

If you have questions feel free to open an issue.

Regards
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Testing and faking ASIO I/O objects

Boost - Users mailing list
On 31 August 2018 at 02:03, Vinnie Falco via Boost-users
<[hidden email]> wrote:

> On Wed, Aug 29, 2018 at 2:03 PM Cristian Morales Vega via Boost-users
> <[hidden email]> wrote:
>> There is any good set of ASIO I/O object fakes available?
>
> Beast experimental interfaces provide testing facilities which meet
> the requirements of the following Asio concepts:
>
>     SyncReadStream
>     SyncWriteStream
>     AsyncReadStream
>     AsyncWriteStream
>
> This is provided by the boost::beast::test::stream class, which works
> with the test::fail_counter class to allow for automated failure
> testing.

This is really useful!

I guess the main things people will miss are:
- Fake Timer: it must be extreme common, to implement network timeouts
- Fake Resolver/Acceptor/Connect to Protocol::endpoint

But it also gives an example of how to implement fakes, so people
should be able to do so for those extra things.

I see you don't allocate read_op using the handler associated
allocator. Is this on purpose? I don't see any problem with this but I
also fail to see other, real, problems when looking at ASIO code and
was afraid of doing it myself.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users