Problem/Motivation

Vimeo went down because of a major Google outage on 2 June 2019. See https://twitter.com/chad_fullerton/status/1135273938601295873

Proposed resolution

Don't connect to external services - we need to stub them.

Fix:

  • Drupal\Tests\media\FunctionalJavascript\MediaStandardProfileTest
  • Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest

See https://www.drupal.org/pift-ci-job/1309043 for example.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Issue summary: View changes
seanb’s picture

Didn't really dive into this too deep, but at a first glance we seem to be missing a call to $this->hijackProviderEndpoints(); defined in Drupal\Tests\media\Traits\OEmbedTestTrait for those tests.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new4.45 KB

This removes the dependency on youtube and vimeo in our tests.

wim leers’s picture

Nice find 😁

I started to review this, but these are some pretty special tests, so I think it'd be better for those who helped create them in the first place to sign off on this.

phenaproxima’s picture

I applied the patch locally and ran MediaStandardProfileTest with my wi-fi turned off. Unfortunately, I still got the same failure as https://www.drupal.org/pift-ci-job/1309043, so I'm not sure the patch is actually fixing the problem...?

alexpott’s picture

@phenaproxima I've run the MediaStandardProfileTest with no internet connection and it passes for me. However the other test Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest fails at a different point...

1) Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest::testWidgetOEmbed
Behat\Mink\Exception\ResponseTextException: The text "No matching provider found." was not found anywhere in the text of the current page.

/Users/alex/dev/sites/drupal8alt.dev/vendor/behat/mink/src/WebAssert.php:787
/Users/alex/dev/sites/drupal8alt.dev/vendor/behat/mink/src/WebAssert.php:262
/Users/alex/dev/sites/drupal8alt.dev/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php:1244
alexpott’s picture

StatusFileSize
new899 bytes
new5.33 KB

With the attached patch both tests pass for me with no connection.

phenaproxima’s picture

Running MediaStandardProfileTest with the patch in #4 applied against 8.8.x HEAD, and wi-fi turned off (I have no other connection to the Internet) gives me this:

Failed asserting that two strings are identical.
Expected :'Drupal Rap Video - Schipulcon09'
Actual   :'example_2.jpeg'

 core/modules/media/tests/src/FunctionalJavascript/MediaStandardProfileTest.php:406
core/modules/media/tests/src/FunctionalJavascript/MediaStandardProfileTest.php:86

EDIT: I get the same failure with the patch in #8.

phenaproxima’s picture

I wonder if this is not an opportunity to kill two birds with one stone: this issue, and #2964636: Improve oEmbed tests.

The problem, really, is that the OEmbed tests are bizarrely written and extraordinarily fragile (I bear a lot of responsibility for this). They should be rearchitected, IMHO, so that all test data is contained in the media_test_oembed module, and simply by enabling that module, everything "just works" for oEmbed tests. The goals should be, in my opinion:

  1. All Media tests should pass without an Internet connection.
  2. The only thing that functional oEmbed tests should need to do in order to work is add media_test_oembed to their $modules array.
  3. OEmbedTestTrait should be deprecated.

This would make me much happier as a Media maintainer. Thoughts?

phenaproxima’s picture

seanb’s picture

I wrote both of the failing tests and apparently it is very easy to do it wrong. It would be great if we can make this a hell of a lot easier. Not sure how big of an effort that would be? I guess having a fix first would at least make sure we don't risk breaking the test bot again when YouTube or vimeo fail. Which should be our main priority now.

phenaproxima’s picture

I wrote both of the failing tests and apparently it is very easy to do it wrong. It would be great if we can make this a hell of a lot easier. Not sure how big of an effort that would be? I guess having a fix first would at least make sure we don't risk breaking the test bot again when YouTube or vimeo fail. Which should be our main priority now.

The monumental shittiness of the oEmbed tests is mostly my fault. Sorry about that. :(

I'd like to refactor them in #2964636: Improve oEmbed tests as I described in #10, and I'm probably in the best position to do that work. In the meantime, though, if both you and @alexpott are getting passing tests on your local systems with this patch applied and the Internet disconnected, I figure that should be enough to stop the bleeding and would be okay RTBCing the current patch as a temporary fix until we can improve things in the other issue.

seanb’s picture

Status: Needs review » Reviewed & tested by the community

Ran the tests multiple times to be sure (with/without the patch in #8). Failed every time without the patch. Green with the patch applied. I think this is good to go.

alexpott’s picture

+++ b/core/modules/media/src/OEmbed/UrlResolver.php
@@ -86,16 +86,13 @@ public function __construct(ProviderRepositoryInterface $providers, ResourceFetc
    * @return string|bool
    *   URL of the oEmbed endpoint, or FALSE if the discovery was unsuccessful.
-   *
-   * @throws \Drupal\media\OEmbed\ResourceException
-   *   If the resource cannot be retrieved.
    */
   protected function discoverResourceUrl($url) {
     try {
       $response = $this->httpClient->get($url);
     }
     catch (RequestException $e) {
-      throw new ResourceException('Could not fetch oEmbed resource.', $url, [], $e);
+      return FALSE;
     }

This looks like a bit like an API change. But we're still conforming to the interface because of the @return. And if this returns FALSE the only code that calls it does this:

    $resource_url = $this->discoverResourceUrl($url);
    if ($resource_url) {
      return $this->resourceFetcher->fetchResource($resource_url)->getProvider();
    }

    throw new ResourceException('No matching provider found.', $url);

so we throw a ResourceException just with a slightly different message which imo is okay.

krzysztof domański’s picture

+1 RTBC I have one suggestion:

--- a/core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php
+++ b/core/modules/media/tests/modules/media_test_oembed/src/Controller/ResourceController.php
@@ -17,17 +17,21 @@ class ResourceController {
    *   The request.
    *
    * @return \Symfony\Component\HttpFoundation\Response
-   *   The JSON response.
+   *   The JSON response or 404 when resources don't exist or are not available.
alexpott’s picture

StatusFileSize
new893 bytes
new5.73 KB

@Krzysztof Domański yeah that's not quite right either though. I think we can just be vaguer - this is only test code so not super important and @phenaproxima wants to refactor it all anyway.

phenaproxima’s picture

Not to derail this issue, but I should mention that I have #2964636: Improve oEmbed tests passing tests, and it allows all oEmbed tests to pass even when the Internet is shut off. So that issue more or less supersedes this one, and greatly reduces the complexity of oEmbed testing. I defer this decision to the committers, but I'm not sure if it would be preferable to commit this patch as-is and stop the immediate bleeding, then reroll #2964636: Improve oEmbed tests...or if we should close this issue, transfer the credit, and finish the other one.

Just thought I'd throw that out there.

larowlan’s picture

I agree with @phenaproxima, making it not rely on the internet in a more complete fashion feels like a better approach - given the likelihood of another vimeo outage is low, perhaps it would be better to focus on that patch instead?

alexpott’s picture

@larowlan it's the same fashion - changing the http client configuration - with just a little less for the developer to think about. Imo we should get this in and then focus on that patch and test it for not connecting to the outside world too because it wouldn't be the first time we've got it wrong.

phenaproxima’s picture

It looks like #2964636: Improve oEmbed tests will be going through its paces now that there's something to iterate, and the priority is preventing core from testing the Internet. So +1 for landing this now.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: 3059022-17.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Random fail that we're seeing in HEAD -

Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest::testWidgetUpload
Behat\Mink\Exception\ResponseTextException: The text "image-1.png" appears in the text of this page, but it should not.
bnjmnm’s picture

StatusFileSize
new5.7 KB

Reroll

dww’s picture

StatusFileSize
new997 bytes

Interdiff between #17 and #24 is failing. So here's a raw diff of the 2 patch files. The only change of substance is that the protected static $modules in core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php was converted to a multi-line array in commit 6e594c26 for #3060603: Live preview is broken when editing the media_library view. Everything else is just context line numbers.

Given that, +1 to leaving this RTBC (although I haven't closely reviewed everything myself).

Cheers,
-Derek

larowlan’s picture

review credits

  • larowlan committed 006e179 on 8.8.x
    Issue #3059022 by alexpott, bnjmnm, dww, phenaproxima, seanB, Krzysztof...

  • larowlan committed fa4a874 on 8.7.x
    Issue #3059022 by alexpott, bnjmnm, dww, phenaproxima, seanB, Krzysztof...
larowlan’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 006e179 and pushed to 8.8.x. Thanks!

c/p to 8.7.x

Status: Fixed » Closed (fixed)

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