Make the last command in `.phpunit-base`'s script overridable
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3572371. -->
Reported by: [wim leers](https://www.drupal.org/user/99777)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>There are systemic issues of random failures for contrib modules ever since Drupal 11.2 — perhaps only for contrib modules whose test suite generates enough load/concurrency. Canvas' is definitely one of those. See <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-1"><a href="https://www.drupal.org/project/gitlab_templates/issues/3500566" title="Status: Active">#3500566: "Directory not empty" warning triggered by something in CI</a></span>.</p>
<p>Quoting @jonathan1055 at <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-2"><a href="https://www.drupal.org/project/canvas/issues/3571997" title="Status: Fixed">#3571997: CI: auto-retry known random Cypress E2E failures + PHPUnit's dreaded "RecursiveDirectoryIterator failed to open directory" (since Drupal 11.2)</a></span>:</p>
<blockquote><blockquote><p>Which means I might have to do what I wrote at the end of #10: override the entire script that <a href="https://www.drupal.org/project/gitlab_templates">https://www.drupal.org/project/gitlab_templates</a> sets</p></blockquote>
<p>If you can make a good case for having that <code>EXIT_CODE</code> optional, set on/off via an environment variable that you control, then Gitlab Templates could implement that, and you would not have to duplicate it all. </p>
<p><strong>Or maybe we have a separate "exit code handling" snippet/reference, which Gitlab Templates would provide, but which a project like yours could override. You would just rewrite the small few last lines, not the entire script section.</strong>
</p></blockquote>
<p>(Emphasis mine.)</p>
<p>This has proven to be necessary, sadly.</p>
<p><strong>For now, Canvas has had to resort to duplicating the entirety of <code>.phpunit-base</code>'s <code>script</code> 🧟</strong></p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>Run intensive contrib test suite on Drupal >=11.2 on GitLab CI.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Allow contrib modules to inject snippet to auto-retry in <code>.phpunit-base</code>. Basically:</p>
<pre> …<br> - cp /var/log/apache2/test.apache.error.log $CI_PROJECT_DIR/apache.error.log.txt<br> # Auto-retry when random failures occur due to upstream bugs.<br> # @see https://www.drupal.org/project/canvas/issues/3571997#comment-16458359<br> - 'grep "RecursiveDirectoryIterator::__construct(/builds/project/canvas/web/sites/simpletest/.*): Failed to open directory: No such file or directory" $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest/phpunit-*.xml && exit 112 || true'<br> - exit $EXIT_CODE</pre><p>
+</p>
<pre> # Auto-retry when random failures occur due to upstream bugs.<br> # @see https://www.drupal.org/project/canvas/issues/3571997#comment-16458359<br> retry:<br> max: 2<br> exit_codes: 112</pre><h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>TBD</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>None.</p>
<h3 id="summary-api-changes">API changes</h3>
<p>TBD</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>TBD</p>
> Related issue: [Issue #3500566](https://www.drupal.org/node/3500566)
> Related issue: [Issue #3571997](https://www.drupal.org/node/3571997)
issue