Problem/Motivation

ResourceTestBase creates its own HTTP client, but inherits the default Guzzle timeout or 30 seconds. This does not use the fix from #2784159: Remove CURL timeout in BTB, which allowed us to close the critical #2844509: Random fails in BrowserTestBase tests with Operation timed out after 30001 milliseconds with 0 bytes.

This has causes occasional random failures; see https://www.drupal.org/pift-ci-job/637415

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#28 interdiff-23-28.txt3.08 KBAnonymous (not verified)
#28 2866056-28.patch2.43 KBAnonymous (not verified)
#23 interdiff-19-23.txt2.06 KBAnonymous (not verified)
#23 2866056-23.patch5.51 KBAnonymous (not verified)
#19 interdiff-14-19.txt1.99 KBAnonymous (not verified)
#19 2866056-19.patch5.25 KBAnonymous (not verified)
#14 interdiff-07-14.txt1.73 KBAnonymous (not verified)
#14 2866056-14.patch5.58 KBAnonymous (not verified)
#7 interdiff-03-07.txt1.63 KBAnonymous (not verified)
#7 2866056-07.patch4.6 KBAnonymous (not verified)
#3 2866056-03-test-only.patch3.05 KBAnonymous (not verified)
#3 2866056-03.patch3.91 KBAnonymous (not verified)
#2 2866056-02.patch877 bytesmpdonadio
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpdonadio created an issue. See original summary.

mpdonadio’s picture

Issue summary: View changes
Status: Active » Needs review
Related issues: +#2784159: Remove CURL timeout in BTB
FileSize
877 bytes
Anonymous’s picture

I don't know we need or not need test for prevent regresion this change, because we haven't test for #2784159: Remove CURL timeout in BTB. But if need, this patch doing it. Interdiff with #2 is test-only patch.

Status: Needs review » Needs work

The last submitted patch, 3: 2866056-03-test-only.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review

#3 is green, so this is Needs Review (the test-only patch was second).

dawehner’s picture

+++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
@@ -136,9 +136,13 @@ public function setUp() {
-    // Set up a HTTP client that accepts relative URLs.
+    // Set up a HTTP client that accepts relative URLs and turns off curl
+    // timeouts.
     $this->httpClient = $this->container->get('http_client_factory')
-      ->fromOptions(['base_uri' => $this->baseUrl]);
+      ->fromOptions([
+        'base_uri' => $this->baseUrl,
+        'timeout' => NULL,
+      ]);

Couldn't this get the HTTP client from the mink instance, which is somewhere in $this->getSession()->client->getClient() or so ...

Anonymous’s picture

Good question. I found two difference in httpClient between mink and ResourceTestBase instance:

  1. 'verify' => FALSE, but maybe ResourceTestBase also not need verify internal resourses.
  2. not set 'base_uri', but maybe we can do it by manual.

But I'm not sure about these assumptions :)

Status: Needs review » Needs work

The last submitted patch, 7: 2866056-07.patch, failed testing.

Wim Leers’s picture

  1. +++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
    @@ -344,7 +344,8 @@ protected function grantPermissionsToTestedRole(array $permissions) {
    -    return $this->httpClient->request($method, $url->toString(), $request_options);
    +    $uri = UriResolver::resolve(uri_for($this->baseUrl), uri_for($url->toString()));
    +    return $this->httpClient->request($method, $uri, $request_options);
    

    Uhm… wow.

    So this is the alternative for not setting base_uri on the Guzzle HTTP client apparently. Wow.

    Let's at least document it.

    Also… ::resolve() expects the base URL second, not first! So AFAICT this can't work.

  2. +++ b/core/modules/rest/tests/src/Functional/ResourceTestBaseTest.php
    @@ -0,0 +1,60 @@
    +class ResourceTestBaseTest extends ResourceTestBase {
    

    I don't think this test is very useful…?

Wim Leers’s picture

Priority: Critical » Normal
Issue tags: +DX (Developer Experience)

Also, I don't see how this is critical?

mpdonadio’s picture

#10, this is causing intermittent failures, which have been classed as criticals b/c disruption to the testing system.

Wim Leers’s picture

Wait, what?!

The IS in #2784159: Remove CURL timeout in BTB says:

While this is not a problem in normal test running, it is a problem when you debug the site using xdebug.

It does not mention random failures. If it was, it'd have been critical too!

I'm confused :(

mpdonadio’s picture

Added in some more related issues that show the history.

Looks like, we made #2784159: Remove CURL timeout in BTB to account for debugging tests.

In #2844509: Random fails in BrowserTestBase tests with Operation timed out after 30001 milliseconds with 0 bytes we finally figured out the 0 byte intermittent was cause by the 30 sec CURL timeout, and we already had an issue about that.

The patch on the first issue got in, and we just closed out the second issue.

I have seen this new issue cause a random failure, https://www.drupal.org/pift-ci-job/637415

Anonymous’s picture

Status: Needs work » Needs review
FileSize
5.58 KB
1.73 KB

#9: document it is not easy for me, but i just tried copy part of /vendor/guzzlehttp/guzzle/src/Client.php buildUri(). ResourceTestBaseTest created only to check 'timeout' => NULL, option.

Retest #7 show 8 errors via use raw $this->httpClient in testPatchDxForSecuritySensitiveBaseFields. Can we replace this case?

Wim Leers’s picture

Priority: Normal » Critical
Issue summary: View changes

In #2844509: Random fails in BrowserTestBase tests with Operation timed out after 30001 milliseconds with 0 bytes we finally figured out the 0 byte intermittent was cause by the 30 sec CURL timeout, and we already had an issue about that.

Thanks for doing that issue queue archeology! Confirming critical status then.

I have seen this new issue cause a random failure, https://www.drupal.org/pift-ci-job/637415

Thanks, that then explicitly confirms this is not just theoretical. Further confirmation of criticalness.

dawehner’s picture

  1. +++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
    @@ -344,7 +344,9 @@ protected function grantPermissionsToTestedRole(array $permissions) {
    +    // Set up a HTTP client that accepts relative URLs.
    +    $uri = UriResolver::resolve(uri_for($this->baseUrl), uri_for($url->toString()));
    +    return $this->httpClient->request($method, $uri, $request_options);
    

    I don't get why we don't force the $url to be absolute. I assume that we then no longer have to do this dance here?

  2. +++ b/core/modules/rest/tests/src/Functional/ResourceTestBaseTest.php
    @@ -0,0 +1,60 @@
    +    $this->assertTrue(30 < $time_end - $time_start);
    

    Can't you use assertLessThan?

Wim Leers’s picture

#16.1: the original intent was for us to be able to do $this->httpClient->request('/node/5?_format=json') for example. Because that'd improve legibility of the tests. But I think we're already generating absolute URLs everywhere. So perhaps we can just remove this support for relative URLs altogether. IOW: +1 :)

dawehner’s picture

#16.1: the original intent was for us to be able to do $this->httpClient->request('/node/5?_format=json')

If we want to support such things we would ideally change the central guzzle client. I believe for now its a more important to fix the critical issue, right?

Anonymous’s picture

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

anavarre’s picture

+++ b/core/modules/rest/tests/src/Functional/ResourceTestBaseTest.php
@@ -0,0 +1,60 @@
+   * Ensures that HTTP client turns off curl timeout.

curl => cURL

Can be fixed on commit.

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work

#18: absolutely! That's what I implied in #17, didn't I? :)

I wanted to confirm RTBC, but I found something small yet questionable:

  1. +++ b/core/modules/rest/tests/src/Functional/EntityResource/User/UserResourceTestBase.php
    @@ -213,7 +213,7 @@ public function testPatchDxForSecuritySensitiveBaseFields() {
    -    $response = $this->httpClient->request('POST', Url::fromRoute('user.login.http')->setRouteParameter('_format', 'json')->toString(), $request_options);
    +    $response = $this->request('POST', Url::fromRoute('user.login.http')->setRouteParameter('_format', 'json'), $request_options);
    

    So here we're removing $this->httpClient

  2. +++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
    @@ -344,7 +342,7 @@ protected function grantPermissionsToTestedRole(array $permissions) {
    -    return $this->httpClient->request($method, $url->toString(), $request_options);
    +    return $this->httpClient->request($method, $url->setAbsolute(TRUE)->toString(), $request_options);
    

    Then why don't we do the same here?

  3. +++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
    @@ -136,9 +136,7 @@ public function setUp() {
    -    // Set up a HTTP client that accepts relative URLs.
    -    $this->httpClient = $this->container->get('http_client_factory')
    -      ->fromOptions(['base_uri' => $this->baseUrl]);
    +    $this->httpClient = $this->getSession()->getDriver()->getClient()->getClient();
    

    Then we could simply delete these lines altogether!

Anonymous’s picture

Many thanks for the tips! Did I understand correctly about httpClient deletion?

Anonymous’s picture

Status: Needs work » Needs review
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Yep!

Reduced API surface. Less chance of breaking contrib/custom tests.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php
@@ -108,4 +108,15 @@ public function renderPipeInLink() {
+    sleep(42);

I don't think we should be adding this test in this issue. If the main test http client has a timeout of 30 secs then we'd have way more test fails. The fault here was creating a new client in ResourceTestBase - swapping to use the main test http client is the fix.

alexpott’s picture

Re #26 - it is great that you've proved the fix in this issue.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
2.43 KB
3.08 KB

For clarity, I'm not a fan of this test too. Because it more clogs, than improves the module. So no problem :)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 3e20814 to 8.4.x and f72d600 to 8.3.x. Thanks!

  • alexpott committed 3e20814 on 8.4.x
    Issue #2866056 by vaplas, mpdonadio, Wim Leers, dawehner:...

  • alexpott committed f72d600 on 8.3.x
    Issue #2866056 by vaplas, mpdonadio, Wim Leers, dawehner:...
Wim Leers’s picture

I already raised my concerns about this test in #9.2, I'm glad it was not committed :)

Glad to have this in!

xjm’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.