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

core_course_external_testcase::test_duplicate_course fails on Windows




      I was getting really odd unit test failures on Windows.

      The error was

      PHP Warning:  unlink(C:\Temp\phpunitdata_head/temp/backup/ca7db3c6c065317c0993e03a7cada794.log) [<a href='function.unlink'>function.unlink</a>]: Permission denied in C:\Users\tjh238\workspace\moodle_head\lib\moodlelib.php on line 10331

      and once it started, every test after that was failing (about 1000 of them).

      As you can see, absolutely no clue which test was failing (note MDL-34893) so I had to put in my own debugging.

      That let me track it down to core_course_external_testcase::test_duplicate_course. This uses backup and restore code to duplicate a course.

      The reason C:\Temp\phpunitdata_head/temp/backup/ca7db3c6c065317c0993e03a7cada794.log could not be unlinked is because something has that file open, and Windows (unlike Linux) does not let you delete open files.

      What has that file open? Well, backup/util/loggers/file_logger.class.php open the file in the constructor, and only closes it in the destructor.

      The backup code has huge nubmers of circular references between classes, so the file_logger is not garbage-collected until the end of the script. Thus the file stays open.

      You can 'fix' this issue by adding to call to gc_collect_cycles(); at the end of test_duplicate_course. However, I suspect that web services should not be using file_logger. Perhaps error_log_logger would be better. Who knows.


          Issue Links



              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created:
                  Fix Release Date: