0
votes

To test our PHP backend we use PHPUnit (v7.3.5) and the GuzzleHttp (v6.3.3) extension for the interface tests.

I'm new to all this stuff and played a little bit arround. I would like to send concurrent requests, but I have to use the cookie feature too.

The concurrency works perfectly and I'm successful with the cookies too. But if i combine both, the concurrency is lost.

My code so far:

// create session 
$jar = new \GuzzleHttp\Cookie\CookieJar;

// create client
$client = new Client([
    'base_uri' => 'http://localhost',
    'cookies' => $jar,   
]);

// login
$client->get("index.php", [
    'form_params' => [
        'usr' => 'myUserName',
        'pwd' => '#myPass*'
    ],
]);

// fill up request array
$requests = new array(
    new Request('GET', 'myPage1'),
    new Request('GET', 'myPage2'),
    new Request('GET', 'myPage3'),
    new Request('GET', 'myPage4'),
    new Request('GET', 'myPage5'),
    new Request('GET', 'myPage6'),
    ...
    new Request('GET', 'myPage100'),
);

// create pool
$pool = new Pool($client, $requests, [
    'concurrency' => 5,
    'fulfilled' => function ($response, $index) {...},
    'rejected' => function ($reason, $index) {...}
]);

// wait until all request are sent
$promise = $pool->promise();
$promise->wait();

If I comment out // 'cookies' => $jar, the concurrency works perfectly.

Is it not possible to achieve both or do I miss something?

CLOSED

It turned it out that the problem wasn't the test itself.
I'm running into the session_start() lock on the server.
And of course without a session, there is no lock...that explain everything

1

1 Answers

0
votes

You might need to run the test in separate process adding the directive in the comment of your test function:

/**
 * @runInSeparateProcess
 */
public function testYourTestFunction()
{
    // Test code here
}