Feel free to change to a feature request or support request as needed.

My understanding was that all tests are run in a clean drupal environment but that is not the case. I just did a heavy debugging session to finally realize that a node_revisions test was failing because i had set a personal timezone in my account and thus a format_date() call was returning a different value for the simpletest user than for myself in the .test file which runs under whomever is logged in. It looks like setUp() makes a new drupal install and then runs the test but i can't figure out why my own uid is active in the .test file.

I hope I am seeing this right and not making a fool of myself.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Title: Failure to setup a clean environment » setUp should also clean-up $GLOBALS['user']
Status: Active » Needs review
FileSize
1.45 KB

moshe, can you try something like this?

chx’s picture

Title: setUp should also clean-up $GLOBALS['user'] » Failure to setup a clean environment
Status: Needs review » Active

Another issue where $GLOBALS/static (which are the very same mechanism in PHP just static has a scope limitation btw.) causes problems. drupalLogin needs to do a full user switching: disable session writes, switch users. Same for drupalLogout (if we have one but i suspect we do).

moshe weitzman’s picture

Status: Active » Needs work

damien - that looks good at first glance. could you add the session write code as mentioned at http://drupal.org/node/218104

Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
1.51 KB

Thanks for the pointer. Here's an updated patch.

Damien Tournoud’s picture

On IRC, moshe suggested to simply load the uid 1 from the tested site. So moved to loading after variable cleaning. Here is an updated patch.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

This fixed the revisions failures and created no new failures. Code looks good so RTBC.

chx’s picture

Priority: Normal » Critical

Agreed and then some.

Dries’s picture

The problem with this is that we might have to pull similar tricks for every global in every module that one wants to test (not just the core modules). This doesn't look like a scalable solution ... a more generic fix is in order, IMO. For example, does it make sense to iterate over every global and to unset it? :P

Damien Tournoud’s picture

We really should only run testing from a clean source environment. PHP doesn't allow unloading functions, so we can't really guarantee that except by controlling every aspect of that environment.

What I would do: add a test.php in Drupal root directory, bootstrap a controlled environment from that (like what's done at the top of install.php), and only then create the test environment.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

I think this needs a bit more thought and discussion. The proposed patch does not guarantee a clean environment at all.

moshe weitzman’s picture

Title: Failure to setup a clean environment » Node revisions test fails if admin has a personal timezone offset
Status: Needs work » Reviewed & tested by the community

Damien's suggestion of a test.php is a good start. The details certainly need to be fleshed out. Fixing the 'clean environment' problem is a really big reworking of simpletest.

I didn't really intend to fully solve that when I started this issue. So, I am changing the title and setting to RTBC based on new title. The node revisions test has a bug and this fixes it, without creeping scope too much.

lilou’s picture

Damien's patch #5 still applied to CVS HEAD.

drewish’s picture

FileSize
1.69 KB

here's a clean re-roll, still makes all the tests pass.

drewish’s picture

Status: Reviewed & tested by the community » Needs work

won't apply now that session_save_session() is drupal_save_session()

Dave Reid’s picture

Marked #345979: Node revision tests fail with timezones as a duplicate of this bug, although progress has seemed to have stalled here.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
1.71 KB

Rerolled for HEAD. If this isn't fixed somehow, I see it coming back to bite us once a lot of contrib modules get testing in.

Damien Tournoud’s picture

Better reroll of the same idea.

Dave Reid’s picture

Status: Needs review » Reviewed & tested by the community

Thanks Damien, that's much better for documentation and obviously your diff isn't being wonky on you today. :) All tests are a green from me, let's see what testing bot says.

Dries’s picture

I'm still not 100% on this because it only solves this problem for $user and not for the entire environment.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

boombatower’s picture

boombatower’s picture

Status: Needs work » Needs review

Update session test to reflect changes.

This also correct upload.test failure.

boombatower’s picture

patch..

Dave Reid’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed this fixes node revisions and upload tests both logged in when running simpletest, logged out running simpletest, and running tests from command line as well.

boombatower’s picture

As a note the bot will be forced to sit idle until this patch (or comparable solution) makes it in.

I vote for getting this in and opening an issue to discuss a more scalable solution, rather than leave testing bot in a useless state.

catch’s picture

I've been running into this bug as well recently, with random test failures people start mistrusting the test framework in general, and I'd rather have our patches tested and coverage increase with some not-perfect stuff in simpletest.module making that possible. Also I'm more interested in tidying up some of the (still, hideously) ugly core tests themselves than simpletest internals.

boombatower’s picture

webchick’s picture

Status: Reviewed & tested by the community » Fixed

This is one of those "between a rock and a hard place" issues.

Dries is 110% bang-on that this is simply fixing a symptom of the overall larger problem of "tainting" the test environment. And we really do need to solve this in a clean and proper way.

Unfortunately, when #339929: Move node links into $node->content was committed, it introduced this little line:

+    $this->assertTrue(strpos($teaser, format_plural(2, '1 attachment', '@count attachments')), 'Attachments link found on node teaser.');

And due to the lengthy sleuthing done by boombatower in #348111: Upload.test fails when run from run-tests.sh, we see that this is yet another symptom of this bug. And we can't turn back on the testing bot without it.

When testing bot is disabled, core committing essentially stops, because the alternative is running the entire test suite each patch which takes 20+ minutes, or closing your eyes and committing and hoping you didn't break an edge-case somewhere.

So... for now, I've committed this. :\ And I've asked boombatower to start #348455: Provide a scalable way to ensure a clean testing environment for SimpleTest which is where interested parties should go to fix this in the *proper* way so we don't need any more of these special-case things.

(Dries, please don't hit me. ;) Though if you feel strongly about it, I would be fine with a roll-back, but we probably need a more concrete plan of attack so we can unleash our coders at it.)

Status: Fixed » Closed (fixed)

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