|
Nico I was wondering about files as well... things like assignment submissions that include files. Can we make the generator generate those too? Like perhaps from a store of 'test' files?
The portfolio code needs to test the integration between the caller (eg assignment) writing files (eg submission) and the portfolio plugin picking it up and doing something with it... I have a proposal 4, that is like 3. but more sophisticated. (Actually, I think it is inspired by something Nicolas said in HQ chat over the weekend, but I go into more detail.)
We make a subclass of $DB (call it test_db) that: i) In insert_record, keeps track, for each database table, of the id of each row inserted using this object - do this either in memory, in a file, or on disc. There is a speed/reliability issue here. This list of added rows is local to the current unit test run - so it is a bit like the backupids table, effectively there will be a table with three columns testrunid, tablename and rowid. This based on the assumption that test methods should only update or delete data that they themselves have inserted. If this assumption is true, then my proposed test class would increase the power of the unit tests to check that code does not modify the wrong data. If that assumption is false, then this whole proposal is rubbish. So typical test code would then look like: // before a block of unit tests - perhaps in each test class constructor. // All the test methods, no change required. // After all the tests. This will be slower than 3, but a bit safer in the case that one person is running unit tests while other people are doing things with the site, or where you yourself are doing things with the site while some slow unit tests run. Here are some possible extra features that could be added to the basic four above, but they would not be needed in a first release: v) Possibly, have it so that when a test run starts, if the place where test data ids are stored contains traced of a previous test run that crashed, it automatically cleans up the rows from the old test run? Another thing to consider if it is a good idea. vi) to get round the problem of complex inserts and updates in ii). Provide some assert methods on the test DB class that can be called after some complex SQL, for example assert_record_exists, or assert_record_deleted. These could be used both to check that the complicated SQL did what it was supposed to do in the database, but also be used to update the list of rowids containing test data. Thinking about where to log ids, my preference would be to store them in arrays in memory, so they can be checked quickly, but also write them to a simple plain text file, to enable v). We can also think about how often we call setup_test_db/cleanup_test_db. We could do it once for the whole test run, and that would work, or we could do it more frequently. That would be a bit slower, but would mean that bad side-effect of tests methods are identified more quickly, and are easier to localise. Actually, we can probably do the setup_test_db/cleanup_test_db in the simpletest driver methods, so the test code does not have to think about them at all. After a long brainstorming session in Moodle HQ, here is the consensual decision:
1. DB tables with alternate prefix are required before Unit tests are available. Regarding the cleaning up of data between each tests: 1. Implement a lock so that unit tests can only be performed by one user concurrently In the cleaning up phase, an additional measure is needed to handle cases of fatal error during unit tests.
1. Once at the beginning of the tests, save a flat text file with the highest PKs of all tables.
Nicolas Connault committed 31 files to 'Moodle CVS' - 16/Sep/08 08:19 PM
Please revert this DML prefix change
+public function get_tables($prefix=null) { I tried very hard to prevent access to other tables with different prefixes in DML and this is totally against it. If you need to access other tables, please create a new database object with separate DB connection. Thanks
Nicolas Connault committed 3 files to 'Moodle CVS' - 16/Sep/08 10:35 PM
Nicolas Connault committed 4 files to 'Moodle CVS' - 17/Sep/08 12:40 AM
Mitsuhiro Yoshida committed 6 files to 'Lang CVS' - 17/Sep/08 12:49 AM
Almost finished all this, but hitting a problem with generation of courses: fix_course_sortorder(). It actually deletes/updates records that were NOT inserted during the unit test run. Any ideas on how to overcome this problem?
extremely hacky way would be to examine the stack trace in your overridden DB object and ignore a call from fix_course_sortorder
of course that does mean we can't test it.
martignoni committed 1 file to 'Lang CVS' - 05/Oct/08 03:40 PM
Petr Skoda made changes - 10/Jan/09 08:30 PM
This is a dead end, there is no way this would work reliably - we can not just switch $DB and hope that it will work fine because there are static and global caches and I am planning to add even more caching for performace reasons. There is a real danger that running unittest would somehow affect real moodle data this way.
We will have to undo this and find some other solution I am afraid. This must be solved NOW, if you do not come with some suitable solution I will revert the code myself. starting a refactoring that:
Not sure if separating "safe" and "separate" unit tests is a good idea.
I can imagine one function that being "safe" today (because it doesn't uses DB) can become "dangerous" tomorrow, because we change its internals (so should go to separate unit tests). I guess there is a 99% chance of forgetting to move that test from normal to separate, so there is a 99% chance of people executing it in the wrong (production) environment. I really think tests are a dangerous thing by definition and only should be allowed (all them) if:
Summarizing, we must work to make unittest (all) useful for developers, allowing them to be re-executed safely and so on. But, at the same level, we must enforce the rule of not running them in production servers at all. Simply that. And, if that becomes true... then I cannot imagine any reason for having "normal" and "separate" unit tests. Difficult to maintain IMO. Ciao
Eloy Lafuente (stronk7) made changes - 10/Jan/09 09:24 PM
Petr Skoda committed 10 files to 'Moodle CVS' - 10/Jan/09 10:23 PM
Petr Skoda committed 1 file to 'Moodle CVS' - 10/Jan/09 10:37 PM
Petr Skoda committed 21 files to 'Moodle CVS' - 10/Jan/09 10:47 PM
Petr Skoda committed 1 file to 'Moodle CVS' - 10/Jan/09 10:54 PM
Petr Skoda committed 5 files to 'Moodle CVS' - 11/Jan/09 01:06 AM
Petr Skoda made changes - 11/Jan/09 01:11 AM
Petr Skoda made changes - 11/Jan/09 01:13 AM
Petr Skoda made changes - 11/Jan/09 01:16 AM
Petr Skoda committed 4 files to 'Moodle CVS' - 11/Jan/09 08:19 PM
I agree with Eloy too
and volunteering to do the coding...
Petr Skoda made changes - 16/Jan/09 05:37 AM
alternative solution is to start using PHPUnit instead of unmaintained simpletest....
Martin Dougiamas made changes - 13/Nov/09 04:08 PM
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I think that the other plans are either a ) too slow, meaning people wont use them when they should or b ) too hard to implement, meaning people wont implement them when they should...
I think concurrent use is an ok thing to lose in this case