Page MenuHomePhabricator

Flaky FileImporter test ImporterTest
Open, Needs TriagePublic

Description

Test failure noticed at

https://integration.wikimedia.org/ci/job/wmf-quibble-core-vendor-mysql-php72-docker/55916/console

I was able to reproduce the failure locally. Dumping the relevant Status object, we see:

1) FileImporter\Tests\Services\ImporterTest::testImport
FileImporter\Exceptions\ImportException: Failed to commit operations: <Error, collected 1 error(s) on the way, no value set>
|    1 | backend-fail-alreadyexists | mwstore://local-backend/local-public/archive/7/72/20180624133723!Test-29e7a6ff58c5eb980fc0642a13b59cb9c5a3cf55.png |
/srv/mw/extensions/FileImporter/src/Services/Importer.php:314
/srv/mw/extensions/FileImporter/src/Services/Importer.php:175
/srv/mw/extensions/FileImporter/tests/phpunit/Services/ImporterTest.php:97
/srv/mw/core/tests/phpunit/MediaWikiIntegrationTestCase.php:447

The test routinely puts files in the actual wiki's upload directory, and it fails to clean them up properly.

$ find -name \*29e7\*
./archive/7/72/20180624133723!Test-29e7a6ff58c5eb980fc0642a13b59cb9c5a3cf55.png
./archive/c/c9/20210607070016!Test-29e7a6ff58c5eb980fc0642a13b59csb9c5a3cf55.png
./archive/c/c9/20210607070224!Test-29e7a6ff58c5eb980fc0642a13b59csb9c5a3cf55.png
./archive/c/c9/20210607070248!Test-29e7a6ff58c5eb980fc0642a13b59csb9c5a3cf55.png
./archive/c/c9/20210607070341!Test-29e7a6ff58c5eb980fc0642a13b59csb9c5a3cf55.png
./archive/c/c9/20210607075317!Test-29e7a6ff58c5eb980fc0642a13b59csb9c5a3cf55.png
./c/c9/Test-29e7a6ff58c5eb980fc0642a13b59csb9c5a3cf55.png

If I delete the file archive/7/72/20180624133723!Test-29e7a6ff58c5eb980fc0642a13b59cb9c5a3cf55.png , the test passes. If I create it manually, the test reliably fails. Teardown is probably missed in the case of https://gerrit.wikimedia.org/r/c/mediawiki/core/+/693298 as a result of a separate test failure relevant to the patch.

Tests should only write to a temporary directory. However, core does not provide an easy way to set up a FileRepo pointing to a temporary directory. ApiUploadTest is probably the best example to follow -- it sets up an upload directory using getNewTempDirectory() and so does not need any special tearDown() method. If teardown is somehow skipped, the only consequence is a waste of disk space, subsequent runs will still pass. But we should probably have a method in MediaWikiIntegrationTestCase that does that.

Event Timeline

Thanks for the ticket @tstarling. Yeah this is something I was never really happy with. We should definitely improve that to avoid pollution of the test systems.

I just wonder how often this happens to get a sense of urgency here. If it's not a pressing issues I would put it on the mid-term maintenance list of our team. Otherwise I could add it to our next sprints. Do you run into this somewhat regularly?