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

Reduce sleeps as much as possible in unit tests

    XMLWordPrintable

    Details

      Description

      PHPUnit makes lots of calls to sleep() to ensure that calls to time() return different numbers. This slows down testings considerably. There are 54 seconds worth of sleep() via 34 calls.

      There are complex cards to enable mocking of time() to resolve this issue on a more comprehensive basis.

      In all uses of sleep(), what is really desired is that one second has rolled forward.

      To reduce that, we wait for the second to roll over. So we now wait for the time() function to return a different answer. This will 1/2 the wait time on average. And worst case example it will be no worse than sleep(1).

      There are a number of sleep(2) places that are replaced and will be a performance win regardless.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

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