cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: thought on testing function in select.c

From: Amr Shahin <amrnablus_at_gmail.com>
Date: Wed, 13 Jul 2011 01:28:00 +0300

On Tue, Jul 12, 2011 at 7:42 AM, Julien Chaffraix <
julien.chaffraix_at_gmail.com> wrote:

> >> have a the test to pass file descriptors to Curl_poll. run a separate
> >> thread/process that will write to specified files. make sure Curl_poll
> >> returned and has the correct info set.
> >>
> >> I do feel though that this test is a bit complex, if there are better
> >> ideas please share them.
> >
> > They're really hard to unit test sensibly, yes. The hard part about using
> > threads is that we need to detect and use a threading lib that libcurl
> may
> > not use by itself.
>
> Also it opens a can of worms as now your tests can easily be flakey
> and / or timing depend.
>
> > I guess an alternative approach is to simply use the functions when
> > connecting to a test server using sockets, as we already have such test
> > servers but that's still a pretty complicated setup for a unit test.
>
> Usually the solution to that is to mock your objects. As we are not
> using an object-oriented language, we may want to put replacement for
> the standard library functions and use them instead for the unit
> tests. That should enable us to get good coverage of those.
>
> Julien
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>

Ok, i would like to first start by breaking those function into a bit of
smaller pieces, i can see that they handle two cases where there is a "fine
poll" and there isn't, after that i could do the trivial testing. Then at a
later stage we can think of some way to fool/mock file handler status.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-07-13