SchedulerDrushTest fails on Gitlab-CI but OK on drupal.org

Created on 12 May 2023, over 1 year ago
Updated 25 March 2024, 8 months ago

The SchedulerDrushTest class runs OK on Drupal.org tests but fails on GitLab CI.
Drupal testbot uses Drush 11.5 and GitLab uses 12.999-dev

The original problem that prompted this issue was convertKeyValueToFlag() Argument #2 ($value) must be of type ?string, bool given. This has been fixed, first by adjusting the Scheduler test code (see comment #2), and subsequently by a change in Drush 12.x

The second problem is that of log messages not being collected by DrushTestTraits::getErrorOutput() for detection within a phpunit test (comment #3 onwards)

Drush issue https://github.com/drush-ops/drush/issues/5572

πŸ“Œ Task
Status

Active

Version

2.0

Component

Testing

Created by

πŸ‡¬πŸ‡§United Kingdom jonathan1055

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jonathan1055
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055
    TypeError: Drupal\Tests\scheduler\Functional\SchedulerDrushTest::convertKeyValueToFlag()
    Argument #2 ($value) must be of type ?string, bool given
    called in /builds/project/scheduler/vendor/drush/drush/src/TestTraits/DrushTestTrait.php on line 74
    

    DrushTestTraits has the following in Drush 12

        /**
         * Given an option key / value pair, convert to a
         * "--key=value" string.
         *
         * @param string $key The option name
         * @param string $value The option value (or empty)
         * @return string
         */
        protected function convertKeyValueToFlag(string $key, ?string $value)
    

    Fixed by changing

    -    $this->drush('sch:cron', [], ['nomsg' => TRUE]);
    +    $this->drush('sch:cron', [], ['nomsg' => '1']);
    

    in this commit on 2.x

    This also runs OK on drupal.org CI with Drush 11.5

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    No change on 8.x-1.x but the error is different, and earlier in the testl

        // Run the plain command using the full scheduler:cron command name, and
        // check that all of the output messages are shown.
        $this->drush('scheduler:cron');
        $messages = $this->getErrorOutput();
        $this->assertStringContainsString('Lightweight cron run activated by drush command', $messages, 'Starting dblog message not found', TRUE);
    

    The error is

    1) Drupal\Tests\scheduler\Functional\SchedulerDrushTest::testDrushCronMessages
    Starting dblog message not found
    Failed asserting that '[notice] Message: Scheduler lightweight cron completed.' contains "Lightweight cron run activated by drush command".
    /builds/project/scheduler/tests/src/Functional/SchedulerDrushTest.php:24
    

    It seems that the default message "Lightweight cron run activated by drush command" is no longer being displayed. This could be due to this recent change on drush ?

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Using Drush 12 locally I can replicate the test failure. Using Drush 11 locally the tests pass.

    Messages written in the Scheduler Drush command definition, via $this->messenger->addMessage() are shown and found in phpunit test using $messages = $this->getErrorOutput()

    But the 'activated' messages are written in other places in the code via $this->logger->notice() and these are not now created during phpunit test. But they displayed in the terminal when the command is run manually.

    Tests on GitLab passed OK on 11 May 23:00 UTC using Drush 12.x-dev. But they were failing by 12 May 15:00 UTC with no source code changes.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I have isolated the Drush commit that caused the test failures, by running locally, and removing commits until the tests pass. The last commit which allows the tests to pass is
    047a3eb87 Thu May 11 21:48:15 2023 Handle bool option values in Test trait (#5560)
    https://github.com/drush-ops/drush/pull/5560/files

    The next commit after this causes the test failures
    ce1042ae8 Thu May 11 23:51:44 2023 Create a service adapter for drush.services.yml (#5553)
    https://github.com/drush-ops/drush/pull/5553/files

    It may be that the Drush changes are fine, and the Scheduler tests were doing things wrongly, and getting away with it. But either way this needs resolving.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Update IS to explain the two separate problems.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    The solution will either be to get Drush 12 fixed, or change the way the Scheduler phpunit test assertions are done, or both. In the meantime, now that we have GitLab pipelines running, as a temporary fix we can skip the Drush tests. This will allow the pipeline to pass, and contributors will not get confused/distracted by failing tests.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I have raised a Drush issue here https://github.com/drush-ops/drush/issues/5572

  • πŸ‡ΊπŸ‡ΈUnited States kwfinken Lansing, MI

    getting similar error:
    ArgumentCountError: Too few arguments to function Drupal\scheduler\SchedulerManager::__construct(), 7 passed in /opt/drupal/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and exactly 9 expected in Drupal\scheduler\SchedulerManager->__construct() (line 96 of /opt/drupal/web/modules/contrib/scheduler/src/SchedulerManager.php).

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    getting similar error

    ??? That's not a similar error at all! It has nothing to do with this problem in Drush tests. Please can you open a separate issue.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    For the record, here is the gitlab log from 14 May 2023 (logs are not kept forever on GitLab)

    There were 5 failures:
    
    1) Drupal\Tests\scheduler\Functional\SchedulerDrushTest::testDrushCronMessages
    Starting dblog message not found
    Failed asserting that '[notice] Message: Scheduler lightweight cron completed.' contains "Lightweight cron run activated by drush command".
    
    2) Drupal\Tests\scheduler\Functional\SchedulerDrushTest::testDrushCronPublishing with data set "#node" ('node', 'testpage')
    Scheduled publishing message not found
    Failed asserting that '[notice] Message: Scheduler lightweight cron completed.' contains "Test Page: scheduled publishing of m2rAcHWd91VaWrJYgiMY for publishing".
    
    3) Drupal\Tests\scheduler\Functional\SchedulerDrushTest::testDrushCronPublishing with data set "#media" ('media', 'test_video')
    Scheduled publishing message not found
    Failed asserting that '[notice] Message: Scheduler lightweight cron completed.' contains "Test Video: scheduled publishing of f3hJU8EiAITPBPgD11wL for publishing".
    
    4) Drupal\Tests\scheduler\Functional\SchedulerDrushTest::testDrushCronPublishing with data set "#commerce_product" ('commerce_product', 'test_product')
    Scheduled publishing message not found
    Failed asserting that '[notice] Message: Scheduler lightweight cron completed.' contains "Test Product: scheduled publishing of s96Y5PVeEZW2CrXHJx8L for publishing".
    
    5) Drupal\Tests\scheduler\Functional\SchedulerDrushTest::testDrushCronPublishing with data set "#taxonomy_term" ('taxonomy_term', 'test_vocab')
    Scheduled publishing message not found
    Failed asserting that '[notice] Message: Scheduler lightweight cron completed.' contains "Test Vocabulary: scheduled publishing of jRJPWX1pgqpTDE4jeFvU for publishing".
    
    FAILURES!
    Tests: 6, Assertions: 68, Failures: 5.
    
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    This is a drush bug, reported here https://github.com/drush-ops/drush/issues/5862
    There is a PR to fix it https://github.com/drush-ops/drush/pull/5863
    This solves the problem locally. Before,

    [notice] Message: Scheduler lightweight cron completed.
    

    With the fixed code we get the two mising messages

    [notice] Lightweight cron run activated by drush command.
    [notice] Lightweight cron run completed.
    [notice] Message: Scheduler lightweight cron completed.
    
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    This pipeline from 17 March still fails. It is using Drush 12.4.4

  • Merge request !126Issue #3359998: Drush test failure β†’ (Open) created by jonathan1055
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 8 months ago
    227 pass
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Drush 12.5 has been released, the latest pipeline uses Drush 12.5.1 and it still fails.

Production build 0.71.5 2024