realflash has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Waiting on an asynchronous call during a test
by pryrt (Abbot) on Dec 13, 2021 at 21:48 UTC | |
|
Re: Waiting on an asynchronous call during a test
by zentara (Cardinal) on Dec 14, 2021 at 16:54 UTC |