Plugin unit tests pass individually but fail in group when trying to get course context in event creation

Plugin unit tests pass individually but fail in group when trying to get course context in event creation

by Itamar Tzadok -
Number of replies: 4
All the plugin tests in the group but the first one fail on
dml_missing_record_exception: Can not find data record in database table context.
Both 2.7 and 2.8 latest.

Any ideas anyone?
smile


Average of ratings: -
In reply to Itamar Tzadok

Re: Plugin unit tests pass individually but fail in group when trying to get course context in event creation

by Itamar Tzadok -

Calling advanced_testcase::resetAllData() in the setUp of the events test fixed this problem whatever it was. smile

In reply to Itamar Tzadok

Re: Plugin unit tests pass individually but fail in group when trying to get course context in event creation

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Which plugin?

Anyway, you should not call resetAllData yourself. Instead, you should call resetAfterTest at the start of those tests that will change the database.

(I thought that if you forget to do that, it detected and gave you an error, but clearly not.)

In reply to Tim Hunt

Re: Plugin unit tests pass individually but fail in group when trying to get course context in event creation

by Itamar Tzadok -

Dataform module.

Before the upgrade the tests worked with resetAfterTest and mysql 5.6.12 which had a known problem with reseting table sequences. When the tests stopped working after upgrading Moodle, I upgraded mysql to 5.6.21 but that didn't help. The problem seemed like a caching issue arising from running all these tests as one script (e.g. static variables persist instead of destroyed and recreated). I tried calling accesslib_clear_all_caches_for_unit_testing but didn't help. I revised the plugin code to be able to cleanup static content on demand but that didn't help either. I can appreciate that resetAllData is somewhat an extreme measure but it's the only thing that works so far.

smile

In reply to Tim Hunt

Re: Plugin unit tests pass individually but fail in group when trying to get course context in event creation

by Itamar Tzadok -

The problem can be narrowed down a little more. My events testcase consists of 4 tests:

  • view events
  • field events
  • filter events
  • entry events

The view and field tests loop over all the installed Dataform view and field subplugins respectively.

Each test begins with creating a course and a dataform activity in the course.

Without resetAllData, if I run only this test case, the first test pass and the rest fail on the above mentioned exception. The 'first' in "first test pass" is relative. As is, the view events test pass and the rest fail. If I remove the view events test, then the field events test pass and the rest fail. And so on.

So, it happens with a group of tests even within the same test case. And it is event related issue.

smile