Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: CURLRequest and the slow tests #5593

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions phpstan-baseline.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,6 @@ parameters:
count: 1
path: system/Filters/Filters.php

-
message: "#^Parameter \\#1 \\$seconds of function sleep expects int, float given\\.$#"
count: 1
path: system/HTTP/CURLRequest.php

-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function send(string $method, string $url)

// Do we need to delay this request?
if ($this->delay > 0) {
sleep($this->delay);
usleep((int) $this->delay * 1_000_000);
}

$output = $this->sendRequest($curlOptions);
Expand Down
22 changes: 11 additions & 11 deletions tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ public function testHeaderContentLengthNotSharedBetweenClients()

public function testOptionsDelay()
{
$request = $this->getRequest();
$this->assertSame(0.0, $request->getDelay());

$options = [
'delay' => 2000,
'headers' => ['fruit' => 'apple'],
];
$request = $this->getRequest();
$this->assertSame(0.0, $request->getDelay());

$request = $this->getRequest($options);
$this->assertSame(2.0, $request->getDelay());
}
Expand Down Expand Up @@ -715,20 +715,20 @@ public function testSendWithDelay()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->get('products');

// we still need to check the code coverage to make sure this was done
$this->assertSame(1.0, $request->getDelay());
$this->assertSame(0.1, $request->getDelay());
}

public function testSendContinued()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("HTTP/1.1 100 Continue\x0d\x0a\x0d\x0aHi there");
Expand All @@ -743,7 +743,7 @@ public function testSendContinuedWithManyHeaders()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$output = "HTTP/1.1 100 Continue
Expand Down Expand Up @@ -787,7 +787,7 @@ public function testSplitResponse()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("Accept: text/html\x0d\x0a\x0d\x0aHi there");
Expand All @@ -799,7 +799,7 @@ public function testApplyBody()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setBody('name=George');
Expand All @@ -814,7 +814,7 @@ public function testResponseHeaders()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("HTTP/2.0 234 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there");
Expand All @@ -828,7 +828,7 @@ public function testResponseHeadersShortProtocol()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("HTTP/2 235 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there shortie");
Expand Down
22 changes: 11 additions & 11 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ public function testHeaderContentLengthNotSharedBetweenClients()

public function testOptionsDelay()
{
$request = $this->getRequest();
$this->assertSame(0.0, $request->getDelay());

$options = [
'delay' => 2000,
'headers' => ['fruit' => 'apple'],
];
$request = $this->getRequest();
$this->assertSame(0.0, $request->getDelay());

$request = $this->getRequest($options);
$this->assertSame(2.0, $request->getDelay());
}
Expand Down Expand Up @@ -698,20 +698,20 @@ public function testSendWithDelay()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->get('products');

// we still need to check the code coverage to make sure this was done
$this->assertSame(1.0, $request->getDelay());
$this->assertSame(0.1, $request->getDelay());
}

public function testSendContinued()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("HTTP/1.1 100 Continue\x0d\x0a\x0d\x0aHi there");
Expand All @@ -726,7 +726,7 @@ public function testSendContinuedWithManyHeaders()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$output = "HTTP/1.1 100 Continue
Expand Down Expand Up @@ -770,7 +770,7 @@ public function testSplitResponse()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("Accept: text/html\x0d\x0a\x0d\x0aHi there");
Expand All @@ -782,7 +782,7 @@ public function testApplyBody()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setBody('name=George');
Expand All @@ -797,7 +797,7 @@ public function testResponseHeaders()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("HTTP/2.0 234 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there");
Expand All @@ -811,7 +811,7 @@ public function testResponseHeadersShortProtocol()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
'delay' => 100,
]);

$request->setOutput("HTTP/2 235 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there shortie");
Expand Down