I'm a writing a module to interact with a REST API. It is OAuth2 authenticated, of which one of the steps is to print a callback URL and wait for it to be called by the REST API when the user has authenticated. My problem is in my test scripts. Tests need to start some kind of mock HTTP server to serve the callback URL, then wait for it to be called once, then continue.

The mock HTTP modules I have found (quite logically) have you write an anonymous subroutine to be called when the request comes in, then start the server, at which point the tests continue regardless. I would like the whole thing to be self-contained - a tester shouldn't have to manually start a server before running the tests.

I have tried Test::Fake::HTTPD and then sleep till it fills out a global-ish variable with the contents of the incoming request, but the act of sleeping seems to terminate the child HTTPD process, resulting in:

[Test::TCP] Child process does not block(PID: 156297, PPID: 156296) at /usr/local/share/perl/5.30.0/Test/TCP.pm line 103.

What is the right way to go about this?


In reply to Waiting on an asynchronous call during a test by realflash

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.