Skip to content

Commit

Permalink
Ensure Behat tests abort if updates fail with requirements errors
Browse files Browse the repository at this point in the history
Drush requires the -y flag to run in automated environments because it
prompts with the list of available updates. However it also does an
update requirements check which gets skipped by the same -y option.

This means that our update path in the CI doesn't fail if there are
requirements errors (even though it should, because it causes errors
later in tests that are hard to debug) and our tests against fixture
dumps for specific update scenarios also don't fail.

Until Drush provides a better solution in
drush-ops/drush#5806. We manually go through
the update output and errors if the key sentence for requirements errors
is spotted.
  • Loading branch information
Kingdutch committed Jan 10, 2024
1 parent 319ce06 commit 268a1f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,18 @@ jobs:
drush cset symfony_mailer.mailer_transport.sendmail configuration.host 'mailcatcher' -y
drush cset symfony_mailer.mailer_transport.sendmail configuration.port '1025' -y
# Ensure there are no warnings in the update.log
if grep -E '^>\s+\[warning\]\s' update.log 1>/dev/null; then
# Move the update.log with warnings and status messages to the test output. The text is viewable on GitHub
# too but some people might find it easier to just download the artifact and get digging.
# Ensure there are no warnings or requirements errors in the update.log
if grep -E '^>\s+\[warning\]\s' update.log 1>/dev/null || grep 'Requirements check reports errors. Do you wish to continue?' update.log 1>/dev/null; then
# Move the update.log with warnings/errors and status messages to the test output. The text is viewable on
# GitHub too but some people might find it easier to just download the artifact and get digging.
if [[ "${{ matrix.with_optional }}" == "with-optional" ]]; then
mv update.log behat-test-output/update-with-optional.log
else
mv update.log behat-test-output/update.log
fi
# Abort our testing until the warning is fixed and let our user know why we stopped.
echo "The drush output should not contain any warnings"
# Abort our testing until the warning/error is fixed and let our user know why we stopped.
echo "The drush output should not contain any warnings or requirements errors"
exit 1
fi
Expand Down
8 changes: 7 additions & 1 deletion tests/behat/features/bootstrap/DatabaseContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ public function loadDatabase(string $database_file) : void {
* @When I run pending updates
*/
public function executeUpdates() : void {
$this->drushDriver->drush("updatedb", ['-y']);
$output = $this->drushDriver->drush("updatedb", ['-y']);
// @todo Drush requires -y to continue running updates when the list of updates are presented but -y also bypasses
// the question about requirements check errors so we must manually check for the output until a better solutions is
// found in https://github.com/drush-ops/drush/issues/5806.
if (str_contains($output, "Requirements check reports errors. Do you wish to continue?")) {
throw new \Exception("The update showed requirement errors, manually run the updates using drush against the fixture used for the test to find the errors.");
}
}

/**
Expand Down

0 comments on commit 268a1f0

Please sign in to comment.