Drupal\Tests\canvas\Kernel\Controller\ApiMediaControllersPostTest::testPost fails intermittently in CI with a mismatch on the itok query parameter in the src URL returned by the media upload API. The itok is computed with a date-based upload folder.

First seen here: https://git.drupalcode.org/project/canvas/-/jobs/9609943
and reproduced locally:

❯ ddev exec -d /var/www/html/modules/contrib/canvas composer run phpunit -- tests/src/Kernel/Controller/ApiMediaControllersPostTest.php
> ./tests/scripts/phpunit.sh 'tests/src/Kernel/Controller/ApiMediaControllersPostTest.php'
PHPUnit 11.5.55 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.20
Configuration: /var/www/html/modules/contrib/canvas/phpunit.xml.dist

FF...                                                               5 / 5 (100%)

Time: 00:28.944, Memory: 118.23 MB

There were 2 failures:

1) Drupal\Tests\canvas\Kernel\Controller\ApiMediaControllersPostTest::testPost with data set "Create a new image" ('image', ['gracie-big.jpg', 'Gracie Dog', 'Gracie Dog in its most happy state'], [1, ['::SITE_DIR_BASE_URL::/files/:...xv7Qhl', 'Gracie Dog in its most happy state', 3000, 2595]])
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
     'id' => 1,
     'uuid' => '197d0907-6527-4941-a3e9-9e03163f5f54',
     'inputs_resolved' => Array &1 [
-        'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3Dh5xv7Qhl',
+        'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3DYbWUs9wV',
         'alt' => 'Gracie Dog in its most happy state',
         'width' => 3000,
         'height' => 2595,
     ],
 ]

/var/www/html/modules/contrib/canvas/tests/src/Kernel/Controller/ApiMediaControllersPostTest.php:132

2) Drupal\Tests\canvas\Kernel\Controller\ApiMediaControllersPostTest::testPost with data set "Create a new image without alt nor title" ('image', ['gracie-big.jpg'], [1, ['::SITE_DIR_BASE_URL::/files/:...xv7Qhl', '', 3000, 2595]])
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
     'id' => 1,
     'uuid' => 'dcdc9b19-1be8-4de9-b689-325d4a2b816b',
     'inputs_resolved' => Array &1 [
-        'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3Dh5xv7Qhl',
+        'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3DYbWUs9wV',
         'alt' => '',
         'width' => 3000,
         'height' => 2595,
     ],
 ]

/var/www/html/modules/contrib/canvas/tests/src/Kernel/Controller/ApiMediaControllersPostTest.php:132

FAILURES!
Tests: 5, Assertions: 150, Failures: 2.
Script ./tests/scripts/phpunit.sh handling the phpunit event returned with error code 1
Failed to execute command `composer run phpunit -- tests/src/Kernel/Controller/ApiMediaControllersPostTest.php`: exit status 1

Issue fork canvas-3587922

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

justafish created an issue. See original summary.

justafish’s picture

Status: Active » Needs review
justafish’s picture

Status: Needs review » Reviewed & tested by the community

  • justafish committed 27d4ff11 on 1.x
    tests: #3587922 ApiMediaControllersPostTest fails intermittently due to...
penyaskito’s picture

???

wim leers made their first commit to this issue’s fork.

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.