The simpletest and simpletest_test_id are never cleared and just grow exponentially. This patch clears them after displaying the results and adds them to the clean environment function.

Comments

boombatower’s picture

Status: Needs review » Reviewed & tested by the community

Doesn't break tests as I just ran them all.

damien tournoud’s picture

Status: Reviewed & tested by the community » Needs work

Well it doesn't grow exponentially, just linearly.

Also, could you please move the DELETE query *after* the result set from the previous SELECT query has been used. This is probably valid (PHP caches the whole result set), but it makes me itch.

boombatower’s picture

Are you asking to have these lines removed? If so that is part of the purpose of this patch. To delete the results after they are displayed.

+    db_query('DELETE FROM {simpletest} WHERE test_id = %d', $_SESSION['test_id']);
+    db_query('DELETE FROM {simpletest_test_id} WHERE test_id = %d', $_SESSION['test_id']);

exponentially is figure of speech (at least how I use it)< /note>

damien tournoud’s picture

No, I just ask that they are moved *after* the result set from the SELECT query is fully used, ie. after all the db_fetch_object() calls.

cwgordon7’s picture

I think this patch is very scary. What if one user starts running all tests, and in the middle, another user decides to clean the environment?

I see no real advantages to deleting from the database, and I see possible loss of data (which is a big concern for those of us who take over an hour to run all tests).

boombatower’s picture

If someone cleans environment the tests may get fried anyway as it will kill the current sessions database. That is an edge case that is not supported. The only case when multiple instances of tests should be running is on testing servers as part of t.d.o. The clean environment is used for developers when tests may crash and is used to clean up the mess. In normal operations of simpletest they should never fail.

I will move the deletes to after (on mobile, not dev box).

boombatower’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB

Untested, but essential the same.

boombatower’s picture

Moved version seems to work great.

wim leers’s picture

Coding style issue:

+  $count = db_result(db_query('SELECT COUNT(test_id)
+                                 FROM {simpletest_test_id}'));

And a big consistency issue:

+/**
+ * Clear the test results tables.
+ */
+function simpletest_clean_results_table() {
+  $count = db_result(db_query('SELECT COUNT(test_id)
+                                 FROM {simpletest_test_id}'));
+
+  // Remove test results.
+  db_query('DELETE FROM {simpletest}');
+  db_query('DELETE FROM {simpletest_test_id}');
+
+  drupal_set_message(t('Removed @count test results.', array('@count' => $count)));
+}

There are THREE different ways to describe the same action:
- "clear" in the doxygen
- "clean" in the function name
- "remove" in the code comments and the dsm call.

Leaving at CNR because it's just coding style issues.

boombatower’s picture

StatusFileSize
new1.73 KB

I assume the issue is

+  $count = db_result(db_query('SELECT COUNT(test_id)
+                                 FROM {simpletest_test_id}'));

should be on one line. I just fine

SELECT COUNT(test_id)
FROM {simpletest_test_id}

allot cleaner, but I forget that isn't standard.

Change "Remove" to "Clear" in comments, but clean is to be consistent with clean_evironment which is overarching operation.

wim leers’s picture

I agree that

SELECT
FROM t1
     t2
     t3
WHERE
  AND
  AND
ORDER BY

is much more readable, and I do this myself as well, but for such a simple query the benefit is lost completely :)

chx’s picture

Doing it separately is fine. I did not want to delete once test is over but this is ok.

boombatower’s picture

StatusFileSize
new1.87 KB

After discussion with chx we decided to add a conditional check on variable simpletest_clear_results which isn't displayed UI anywhere, but would be useful down the road if contributed modules wanted to provide analysis on the results.

damien tournoud’s picture

Looks good to me. Where should we document the variable?

boombatower’s picture

Status: Needs review » Reviewed & tested by the community

Tested seems to work great. Anyone want to try it out?

boombatower’s picture

ping.

dries’s picture

Status: Reviewed & tested by the community » Needs work

Patch no longer applies and needs a re-roll.

A code review reveals no issues. Should land after a quick re-roll.

boombatower’s picture

Status: Needs work » Reviewed & tested by the community

It would appear that this has already been committed... hmm??.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Yes, I think I accidentally committed it. Let's mark it fixed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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