Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-53012

Behat: Add step to run scheduled task

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      This test introduces a new Behat step. To check it:

      1. Visit the 'Scheduled tasks' page (under Site settings / Server) on your Behat instance and look at the last run time for the task "core\task\completion_regular_task". Note the time down.
      2. Run behat with --tags=core_badges --name="Award badge on course completion"
        1. EXPECTED: The Behat test should pass (and incidentally, about a minute faster than it used to)
      3. Visit the 'Scheduled tasks' page (under Site settings / Server) on your Behat instance and look at the last run time for the task "core\task\completion_regular_task"
        1. EXPECTED: The task should show that it ran recently, whereas all the other tasks didn't run yet.
      Show
      This test introduces a new Behat step. To check it: Visit the 'Scheduled tasks' page (under Site settings / Server) on your Behat instance and look at the last run time for the task "core\task\completion_regular_task". Note the time down. Run behat with --tags=core_badges --name="Award badge on course completion" EXPECTED: The Behat test should pass (and incidentally, about a minute faster than it used to) Visit the 'Scheduled tasks' page (under Site settings / Server) on your Behat instance and look at the last run time for the task "core\task\completion_regular_task" EXPECTED: The task should show that it ran recently, whereas all the other tasks didn't run yet.
    • Affected Branches:
      MOODLE_29_STABLE
    • Fixed Branches:
      MOODLE_29_STABLE, MOODLE_30_STABLE
    • Pull Master Branch:
      MDL-53012-master

      Description

      Running cron tasks is only currently possible with the 'And I trigger cron' step.

      This step:

      • Cannot be used more than once within a Behat scenario (the second time it won't do anything, because cron and/or the required task already ran)
      • Is slower than necessary as it runs many tasks
      • Means that tests may fail if an unrelated plugin breaks an unrelated cron task

      As a result, it's frequently necessary to create custom tasks for a particular plugin that either mess about with the database in order to ensure a task will run on next cron, or else manually run an individual task.

      Rather than doing all these custom tasks it would be a lot nicer to have a built-in step that does it. I'll write the code for this and see what people think.

      (Obviously this is just something I'd like rather than something we need; creating lots of tasks in all our plugins to do this is a successful workaround.)

      The disadvantage of this is that running a single task is slightly less 'realistic' than running the entire cron, but I think that's a fairly limited disadvantage so it would at least be nice to have the option. In addition, running cron in the browser window is not really a realistic situation because it normally runs in the background - using this step, you have the advantage of being able to run a cron task without a user necessarily having to log out and in again, which may actually provide more realistic testing of some situations.

      Note: As this is a Behat step change, I am submitting all supported branches.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  14/Mar/16