I've found a serious flaw in simpletest. It is related to the fact that although every test creates a new version of its sandbox, the php script is still the same one executing as before.

This can have serious consequences in relation to funcs that cache some or all of their state. I found this bug in particular when dealing with node creation. (or to be more specific, product creation while testing Ubercart)

As you can see in node_load, there is an internal cache that is only reset by either flushing it manually or script termination. In normal scenarios that's exactly what you expect, the script to halt... but testing gives us a new problem... the script is still alive. Now if I create a node, and my test which created it ends, and is tearDown'd, the node cache is still alive...

I solved it by placing this code in my child-of-drupalWebTestCase's tearDown:

    // flush the node cache...
    node_load(NULL, NULL, TRUE);

This could potentially be painful to fix, with functions everywhere holding their own state... As these cases are found that affect the Drupal core, they should be added to drupalWebTestCase's tearDown, and there needs to be a note in the documentation about this issue as well, so that developers know they have to flush their caches in their tearDown's.

Comments

moshe weitzman’s picture

Status: Active » Closed (duplicate)