Currently SimpleTest resets the database by creating a fresh install of Drupal in a prefixed set of tables before every test function is run, but it doesn't reset all environment areas.

I noticed this when updating the upload tests. When files are uploaded and not deleted they just sit in the upload directory even thought the referencing node has been deleted when the database is fried. This is the expected behavior, but causes issues.

Especially if these tests are run on every patch the test servers will get an enormous amount of copied files sitting in the directory. There could be other areas of the environment similar to this, but the database and files directory are two major ones.

I think we need to add some code to tearDown that clears the files directory excluding the simpletest folder. This could be an issue if SimpleTest is intended to run on production server, which I still don't think is a good idea. In order to compensate SimpleTest would need to record a snapshot of the files directory before and after the tests.

Even the above idea could have problems if multiple test sessions are running. I suppose the best idea would be to read the files table and just remove all files based on that, just before the prefixed database is fried. Not sure if there is a function that already does that.

Any comments or possible areas that also need resetting.

Comments

moshe weitzman’s picture

delete all files that are orphaned and are older than 30 days?

boombatower’s picture

chx mentioned possibly changing the files directory to match the db prefix and then simply deleting it when the database is deleted. That would also be handy for scrubbing the environment after tests crash.

This leads into providing a reset environment function that could be called via cron, automatic patch testing API, or using a button for developers.

boombatower’s picture

Assigned: Unassigned » boombatower
Status: Active » Needs review
FileSize
5.57 KB

I made a patch that creates a temporary directory and sets it to the files directory in setUp then when tearDown is called it removes it.

I also changed the button from Clean Database to Clean Environment and re-factored the code accordingly.

The simpletest.module now provides a function simpletest_clean_environment that can be called by cron or by the automatic patch testing framework.

boombatower’s picture

Status: Needs review » Fixed
FileSize
6.18 KB

Committed.

chx suggested that the button be moved to another tab with a confirm page.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.