After implementing some massive tests elsewhere, which failed for entirely invisible reasons, I had to invent something.

The fails were caused by invalid XML-RPC data, which resulted in a error response from the XML-RPC server, but the module that is tested implements a failover mechanism to not expose such errors.

But of course, those errors were logged. But when running web tests, you can't look into the logs.

So why don't we look always into the logs?

If your test expects a failing watchdog message, then it can pre-emptively invoke $this->assertWatchdogMessages(FALSE), which applies the identical assertion logic reversed (fails will pass).

Subsequent calls will only assert new watchdog messages.

So let's see what failures we have under the hood. :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

Anonymous’s picture

subscribe.

sun’s picture

Status: Needs work » Needs review
FileSize
2.9 KB

Alrighty - to make any sense out of those fails, we also need the $type of each message.

sun’s picture

Catch all. :)

sun’s picture

Fixed the docs.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Status: Needs work » Needs review

Created #652420: Fix errors uncovered using aggressive watchdog assertion to fix the actual failures, so we can focus on this thingy in here.

sun’s picture

errr. Fixed the incomplete logic for checking whether {watchdog} exists before trying to query it ;)

Status: Needs review » Needs work

The last submitted patch failed testing.

Dries’s picture

+++ modules/simpletest/drupal_web_test_case.php	6 Dec 2009 07:37:40 -0000
@@ -1224,6 +1227,62 @@ class DrupalWebTestCase extends DrupalTe
+   *   (optional) Boolean whether a non-severe watchdog messages are expected.

Typo: a ... messages -- singular/plural mix up.

+++ modules/simpletest/drupal_web_test_case.php	6 Dec 2009 07:37:40 -0000
@@ -1224,6 +1227,62 @@ class DrupalWebTestCase extends DrupalTe
+  protected function assertWatchdogMessages($pass_expected = TRUE, $type = NULL) {

Instead of $pass_expected, I was expecting a string to match. Like:

assertWatchdogMessage('hello world', 'comment');

The API is a bit unexpected for me, and not as intuitive as the example above.

+++ modules/simpletest/drupal_web_test_case.php	6 Dec 2009 07:37:40 -0000
@@ -2613,12 +2672,25 @@ class DrupalWebTestCase extends DrupalTe
+   * @param $assert_watchdog
+   *   (optional) Boolean whether to automatically assert expected watchdog
+   *   messages for 403 and 404 codes.
+   *

This seems to be scope creep to me, and pollutes the assertResponse() API. It is nicer if the assertResponse() API wasn't inter tangled with watchdog. I'd keep them separate.

sun’s picture

Note, this aggressive watchdog logging proposal is not to be confused with #500394: Add new log fetcher, which attempts to allow to retrieve individual log messages.

Status: Needs work » Needs review

sun requested that failed test be re-tested.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

I'm continuing to fix patch failures in #652420: Fix errors uncovered using aggressive watchdog assertion. Just wanted to mention once again:

This is totally awesome.

One of the failing Locale tests revealed an utterly wrong test. :)

Will this pass?

    // Verify language selection is not present on add article form.
    $this->drupalLogin($web_user);
    $this->drupalGet('node/add/article');
    // Verify language select list is not present.
    $this->assertNoRaw('<select name="language" class="form-select" id="edit-language" >', t('Language select not present on add article form.'));

Sure it will! An "Access denied" page contains no language selector! :-D

Status: Needs work » Needs review

sun requested that failed test be re-tested.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Created #653940: Clean-up: Tests do not report all errors to fix SimpleTest's error reporting.

sun’s picture

Some code by Damien Tournoud, which might fix those wrong source function identifiers in the test result:

diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 3ed4983..136922b 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
 -185,18 +185,26 @@ abstract class DrupalTestCase {
    *   Array representing the true caller.
    */
   protected function getAssertionCall() {
-    $backtrace = debug_backtrace();
+    $full_backtrace = debug_backtrace();
+    $backtrace = $full_backtrace;
 
     // The first element is the call. The second element is the caller.
     // We skip calls that occurred in one of the methods of our base classes
     // or in an assertion function.
-   while (($caller = $backtrace[1]) &&
+   while (!empty($backtrace[1]) && ($caller = $backtrace[1]) &&
          ((isset($caller['class']) && isset($this->skipClasses[$caller['class']])) ||
            substr($caller['function'], 0, 6) == 'assert')) {
       // We remove that call.
       array_shift($backtrace);
     }
 
+    if (empty($backtrace[1]) || $backtrace[1]['function'] == 'simpletest_script_run_one_test') {
+      // The backtracing failed: we reached the bottom of it. That means that
+      // this assertion occured inside simpletest itself. Do not remove any
+      // call in that case.
+      $backtrace = $full_backtrace;
+    }
+
     return _drupal_get_last_caller($backtrace);
   }
carlos8f’s picture

wow. subscribe

catch’s picture

subscribing.

sun’s picture

Actually, the nice thing about this patch is that the fails reported in the test results are entirely different to the notices, warnings, and errors that #653940: Clean-up: Tests do not report all errors revealed.

Hence, combining both will make our tests *really* bullet-proof. I really look forward to that.

I'll continue here, when #653940: Clean-up: Tests do not report all errors has landed.

sun’s picture

Status: Needs work » Needs review
FileSize
9.02 KB

Discussed this some more with smk-ka and carlos8f... we actually think that every request in the internal browser should directly catch any severe messages.

Attached patch implements this as prototype.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

So the nice thing about this approach is that you see the actual + real location of the test code that triggered the watchdog message:

access denied: user/3/contact      Watchdog     contact.test    312     ContactPersonalTestCase->testPersonalContactAccess()

So you go in there and you see:

    // Test denied access to the user's own contact form.
    $this->drupalGet('user/' . $this->web_user->uid . '/contact');

However, I can perfectly see how this new approach will trigger uneasy feelings... but OTOH, I can't think of a better location and way to do it.

Of course, the name of the key I added to $options is highly debatable, and of course, the inlined logic in assertResponse() is no longer required. And we likely want to replace the value for the $options key with a string that's passed as $type to assertWatchdogMessages(), so we don't do a catch-all style assertion in case we expect a certain fail.

sun’s picture

Status: Needs work » Needs review
FileSize
16.61 KB

And this is how it would look like.

I didn't update everything, because I need to know whether we want to go with this approach first.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
16.7 KB

errr, I really hate my copy + paste mistakes :P

Status: Needs review » Needs work

The last submitted patch failed testing.

Status: Needs work » Needs review

Re-test of from comment #2364114 was requested by @user.

Status: Needs review » Needs work

The last submitted patch, drupal.assert-watchdog.27.patch, failed testing.

sun’s picture

Category: feature » task

We need an agreement on this approach to move forward here.

Note that this was implemented in a contributed module already, which revealed a bug: $seen_ids cannot be cached statically within the function, because the {watchdog} table is thrown away for each test that is run.

sun.core’s picture

Priority: Critical » Normal

This is badly needed and still can be considered, but it's Not critical. Please read and understand Priority levels of Issues, thanks.

Dave Reid’s picture

I've also implemented this in my own contrib module and it's exposed a core bug already: #775012: Theme key watchdog errors on node pages. We can't allow core to ship with random error messages on every singe node edit view or something as commonly viewed. I don't think this should be linked to drupalGet() however.

Dave Reid’s picture

@33 LOL at giving yourself the lashing since no one else but 'sun' set this to critical. :)

sun’s picture

The idea is that we do not expect any severe watchdog messages on any GET/POST request, unless explicitly specified. Therefore, this approach automatically covers any possible scenario and reveals unexpected messages in any request that is performed during testing.

sun’s picture

Version: 7.x-dev » 8.x-dev
valthebald’s picture

smartango’s picture

I am sorry to be not exactly on topic, but I experiencing this and make all site break.

For example when I try to search for an invalid utf8 string, system raise exception and site give awful page (innodb exception). Also I read #393538: Document that check_plain() can issue PHP messages on invalid UTF-8 input thread and I realized that I have to add @ on front of check_plain if I want url with utf8 works.

Why does a keyboard character is not utf8 valid code? there is a problem with html encode (http header, html header..)? should be fixed there? what the test would to say and what actions are to be taken is not clean, not here, neither in other report ..

Incidentally I found dblog_watchdog do not call check_plain on location field (nor in referer) I added utf8_encode() there, it seems to work, it seems, in fact this is broken when there are result, so I have to add utf8_encode to search.module (search_simplify() now).

I understand it is very important to define a good test, but at this time I could not go online with drupal 7.14 (who can?) I can disable watch dog, maybe most site want to use solr, it solve? who can use it in a entry hosting?

Finally I ask if at least against dblog and search modules should be filed a bug report, and if those have to call check_plain, give error, translate, have some kind of behaviour, or what. Error on search string is not acceptable. From user prospective it is fail, customer would not pay if a site give error on search, and you know what? he is right on this.

I am just going to make a patch that works, apply it on current drupal version and maintain it internally for web company I am working for .. is this the way opensource is supposed to work?

I appreciate the TDD, defining test is important, and I appreciate the work is done here, I just want to give a wider view of what invalid utf8 error means.

Damien Tournoud’s picture

@smartango: I assume you are using IIS. See how to configure IIS not to mangle the encoding of server variables. This is a bug in IIS, not Drupal.

valthebald’s picture

#40: controversial behavior of htmlspecialchars() is the same on IIS and Apache/nginx.
It just behaves opposite to desired: when display_errors is on, it is silent (but other functions throw messages); when display_errors is off, it throws messages.
It's a proper #phpwtf, and I think the only way to overcome it is to suppress htmlspecialchars() call output with @

smartango’s picture

@Damien why this bug is absent in Drupal 6? (same IIS)

Damien Tournoud’s picture

@smartango: Drupal 6 is very lenient. You probably have the same bug but never actually noticed it.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Component: simpletest.module » phpunit
Issue summary: View changes

Triaging issues in simpletest.module to determine if they should be in the Simpletest Project or core.

This looks like it a Phpunit issue, changing component.

jonathanshaw’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2903456: Allow kernel tests to fail or expect logged errors

Closing in favour of #2903456: Allow kernel tests to fail or expect logged errors which is newer, but the discussion here is outdated.