Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Title: run-tests.sh and Simpletest attempt to run abstract/base test classes » run-tests.sh attempts to run abstract/base test classes
Assigned: Unassigned » sun
Status: Active » Needs review
FileSize
736 bytes

Attached patch should fix the issue.

aspilicious’s picture

Don't know the internals of the $test_classes array but my feeling says this should be good to go.

sun’s picture

Let's make that more solid.

$ php core\scripts\run-tests.sh --php php --url http://drupal8.test/ --class Drupal\node\Tests\NodeTestBase
  ERROR: No valid tests were specified.
sun’s picture

+      // This is the last line of defense.

@sun shouldn't listen to metal while hacking. ;)

sun’s picture

Priority: Major » Critical

Hm. This bug impacts existing, regular projects:
http://qa.drupal.org/pifr/test/305443

sun’s picture

Priority: Critical » Major

I redact that statement. The test failure is caused by advanced usage of PSR-0 classes in that contrib module.

sun’s picture

It is unfortunate that we have to load all test classes in order to check whether they have a ::getInfo() method, but I do not see another way around this.

In other words, I think this patch is RTBC.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

I think this is rtbc to.

catch’s picture

It is unfortunate that we have to load all test classes in order to check whether they have a ::getInfo() method, but I do not see another way around this.

What about reflection? Not sure it matters though, run-tests.sh is definitely not the bottleneck in running tests.

sun’s picture

Sure, Reflection works, too. :)

$ php core\scripts\run-tests.sh --php php --url http://drupal8.test/ --class Drupal\node\Tests\NodeTestBase
  ERROR: No valid tests were specified.

$ php core\scripts\run-tests.sh --php php --url http://drupal8.test/ --class Drupal\node\Tests\NodeFeedTest,Drupal\node\Tests\NodeTestBase

Drupal test run
---------------

Tests to be run:
 - Node feed (Drupal\node\Tests\NodeFeedTest)

Test run started:
 Friday, July 27, 2012 - 16:32

Test summary
------------

Node feed 1 pass, 0 fails, and 0 exceptions

Test run duration: 9 sec
aspilicious’s picture

? This still needs to load every test. Catch wanted to use reflection when building the list.

sun’s picture

There is no other location where the list of classes to run is built. Actually, when passing definite arguments (and not the --all parameter), then there is no predefined list involved at all. That is, because we recently optimized run-tests.sh script for the new class loader: #1683884: Update, simplify, and speedup run-tests.sh for PSR-0, and allow to run all tests of a module

The idea of using Reflection is that PHP might have the class information pre-cached natively (or potentially, that's only possible when APC is enabled [on the command line though?]).

Anyway, as @catch already mentioned, that's the very least of test performance issues we should care for...

aspilicious’s picture

Ok lets commit #10 so views D8 tests can run again

chx’s picture

Note: if we commit #10 then soon-ish #1698108: Update Drupal's dependencies we can use the tokenizer code I wrote for Doctrine to replace the ReflectionClass with a tokenizer-based approach so that you do not need to include all the classes (yet you need to read them, yes). It was meant for annotations but seems useful here as well. See an example here on how this is done.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs review

Testbot cannot instantiate an abstract class, because they are abstract. PHP will not allow it. The problems we had in Views were solved by properly making base classes abstract.

I think this should be closed, but leaving open for discussion.

sun’s picture

@tim.plunkett: This code does not attempt to instantiate an abstract class. In fact, it is the essential fix to make the test runner not attempt to do that.

aspilicious’s picture

sun when you make the base classes abstract the test runner won't attempt to do it.

tim.plunkett’s picture

FileSize
1.24 KB
1.44 KB

I think checking for getInfo is incorrect. This makes more sense to me.

tim.plunkett’s picture

However, I don't think this is actually legitimate, core and contrib are full of abstract classes that aren't blowing up on testbot.

xjm’s picture

Issue tags: +Needs manual testing
xjm’s picture

Sorry for double post. :)

xjm’s picture

I should note that I'm particularly concerned about automatically skipping any getInfo()-less class -- I think this would mean (as Tim has stated) that a broken test without a getInfo() method would silently never be run, which is a concern, as no one will typically scan through all 450 core tests classes to ensure one has run. However, I'm going to actually get some manual testing with this issue to see what's happening.

xjm’s picture

Threw together a sandbox. Haven't actually tested with it yet.
http://drupal.org/sandbox/xjm/1705218

Base classes should be abstract. Tim mentioned yesterday that 25 in core currently are not, and that #1674290: PSR-0 tests in contrib modules are not found was caused by a views bug.

sun’s picture

Status: Needs review » Reviewed & tested by the community

A missing getInfo() is (sadly) "catched" on various other levels of the callstack, so I'm fine with this compromise.

The original idea and intention was that run-tests.sh is and should be a detached test runner script that does not rely on the gazillions of weird functions and checks of simpletest.module in the first place.

Since that is a never-ending battle and my plan is to replace the testing framework entirely for D8 anyway, I'm happy to go with this patch as a(nother) stop-gap fix.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
15.08 KB

Sorry, which patch are you RTBCing? I'd much rather just do this.

Status: Needs review » Needs work

The last submitted patch, drupal-1700682-25.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
14.47 KB

Fixed my regex, I accidentally marked NodeAccessBaseTableTest as abstract :)

Status: Needs review » Needs work

The last submitted patch, drupal-1700682-27.patch, failed testing.

tim.plunkett’s picture

Call to undefined function Drupal\system\Tests\Upgrade\language_negotiation_include()

I think I've seen that before, can't remember where.

aspilicious’s picture

Core is broken cause of a missing contact.settings.yml file. And missing config files lead to this error in upgrade tests.

catch’s picture

Status: Needs work » Needs review

#27: drupal-1700682-27.patch queued for re-testing.

sun’s picture

This is getting a bit exasperating. Correcting all those tests throughout core is nice, but can you explain how that fixes the topic of this issue?

tim.plunkett’s picture

If the classes are abstract, run-tests.sh will happily ignore them. Because PHP won't let it do anything but ignore it.

The only error run-tests.sh has ever given on this topic is when a non-abstract class with a missing getInfo is run.

Those errors should continue to cause fatals, because that is an invalid test class.

sun’s picture

If the classes are abstract, run-tests.sh will happily ignore them. Because PHP won't let it do anything but ignore it.

Which code makes run-tests.sh ignore them?

tim.plunkett’s picture

FileSize
15.02 KB

Compromise. Combines #18 and #27, without the duplicated hunk in run-tests.sh.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Fine with me.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

This looks good but the patch no longer applies. Asking for a re-roll:

vortex:drupal dries$ git apply ../f.patch 
error: patch failed: core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php:12
error: core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php: patch does not apply

Not sure why this is 'major'. Should probably be 'normal', unless explained otherwise.

tim.plunkett’s picture

Status: Needs work » Postponed

Conflicted with #1380958: Replace $modules list for WebTestBase::setUp() with ::$modules class properties. It will also conflict with the list of patches in #1711070: Convert tests to use ::$modules property instead of parent::setUp($modules), so if it's okay with sun, I'm going to postpone this.

sun’s picture

Priority: Major » Normal
Status: Postponed » Reviewed & tested by the community
Issue tags: -Needs issue summary update, -Needs manual testing
FileSize
15.03 KB

Re-rolled against HEAD. There shouldn't be many conflicts either way. We definitely need to fix the test runner script.

tim.plunkett’s picture

Yeah, and those other issues have to all be rerolled it turns out for doc blocks, proceed!

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thanks!

sun’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)
Eric_A’s picture

It appears this killed d.o. contrib testing. Would that be a --file option issue or a PIFR issue?

Output: [ReflectionException: Class Drupal\chessboard_filter\Tests\ChessboardFilterTest does not exist in ReflectionClass->__construct() (line 554 of /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh).].

On a side note: for the --file option the abstract classes were already being excluded by regex.

sun’s picture

Version: 7.x-dev » 8.x-dev
Status: Patch (to be ported) » Active

huh?

Can you clarify where this test is located? http://drupal.org/project/chessboard_filter yields a 404.

Eric_A’s picture

The test is here: http://qa.drupal.org/pifr/test/310618 (Chessboard Filter is a module in the Chessboard project: drupal.org/project/chessboard)

But how about a reasoning like this: my test class cannot be auto-loaded here unless the namespace is registered and that won't happen until the module is enabled. The module will not be enabled until the test class object is alive.
So the code block that deals with the --file option needs to call simpletest_classloader_register() just like simpletest_test_get_all() does.

EDIT: Though it does not make much sense to register disabled modules namespaces when you're not going to run all tests but just the ones from the explicitely passed (PSR-0) files.

sun’s picture

Version: 8.x-dev » 7.x-dev
Status: Active » Postponed

That's an excellent analysis, @Eric_A.

The root cause for that is actually not this issue/patch, but much rather #1683884: Update, simplify, and speedup run-tests.sh for PSR-0, and allow to run all tests of a module

Essentially, this patch here unintentionally revealed that some PSR-0 test classes may not be loadable, and run-tests.sh (unintentally) throws an appropriate error now.

xjm’s picture

This same error shows up in the log for Views on QA:

Output: [ReflectionException: Class Drupal\views\Tests\Style\PluginStyleJumpMenuTest does not exist in ReflectionClass->__construct() (line 554 of /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh).].
xjm’s picture

Version: 7.x-dev » 8.x-dev
Status: Postponed » Needs review

I confirmed checking out the commit before the one in this issue allows views tests to be run again. It is not possible to run any views tests with this patch.

Can we revert this commit until we sort the issue out?

xjm’s picture

Actually, rather than reverting it, let's just revert the change to run-tests.sh. The rest is legit.

xjm’s picture

FileSize
566 bytes

And next time let's please test the script manually before committing changes to it. :)

Status: Needs review » Needs work

The last submitted patch, run-tests-1700682-52.patch, failed testing.

tim.plunkett’s picture

I did test this manually, and it worked fine.

I think this might be a PHP version issue?
I'm using 5.3.13, can someone test with 5.3.3?

xjm’s picture

I have 5.3.6 and get the same error as on the bot. Checking the bot's php version in #1635240-4: Disregard -- patch testing issue ☢.

xjm’s picture

So I don't think this is actually related to the PHP version; just to what modules are enabled in the parent environment. The classes are not detected when (in our case) views and ctools are disabled.

[lorentz:vdc | Mon 20:38:09] $ php core/scripts/run-tests.sh --url 'http://localhost:8888/vdc'  --file sites/all/modules/views/lib/Drupal/views/Tests/Style/PluginStyleJumpMenuTest.php

Drupal test run
---------------

Tests to be run:
 - Jump menu (Drupal\views\Tests\Style\PluginStyleJumpMenuTest)

Test run started:
 Monday, August 6, 2012 - 20:38

Test summary
------------

Jump menu 6 passes, 0 fails, and 0 exceptions

Test run duration: 4 sec

[lorentz:vdc | Mon 20:38:46] $ drush dis views -y
The following extensions will be disabled: views
Do you really want to continue? (y/n): y
views was disabled successfully.                                     [ok]
[lorentz:vdc | Mon 20:39:08] $ drush dis ctools -y
The following extensions will be disabled: ctools
Do you really want to continue? (y/n): y
ctools was disabled successfully.                                    [ok]
[lorentz:vdc | Mon 20:39:13] $ php core/scripts/run-tests.sh --url 'http://localhost:8888/vdc'  --file sites/all/modules/views/lib/Drupal/views/Tests/Style/PluginStyleJumpMenuTest.php
ReflectionException: Class Drupal\views\Tests\Style\PluginStyleJumpMenuTest does not exist in ReflectionClass->__construct() (line 554 of /Applications/MAMP/htdocs/vdc/core/scripts/run-tests.sh).
[lorentz:vdc | Mon 20:41:26] $ git apply run-tests-1700682-52.patch
[lorentz:vdc | Mon 20:41:29] $ php core/scripts/run-tests.sh --url 'http://localhost:8888/vdc'  --file sites/all/modules/views/lib/Drupal/views/Tests/Style/PluginStyleJumpMenuTest.php

Drupal test run
---------------

Tests to be run:
 -  (Drupal\views\Tests\Style\PluginStyleJumpMenuTest)

Test run started:
 Monday, August 6, 2012 - 20:41

Test summary
------------

Jump menu 6 passes, 0 fails, and 0 exceptions

Test run duration: 4 sec

[lorentz:vdc | Mon 20:41:37] $ 
xjm’s picture

Status: Needs work » Needs review

Earlier fail was a bot goof.

xjm’s picture

Issue tags: +Needs manual testing

Steps to test manually:

  1. Install 8.x core and enable simpletest.
  2. Download a contributed module with an 8.x test suite (and any dependencies) into the copy of 8.x, but do not enable the module.
  3. Use the run-tests.sh command to run a test from the module, e.g.:
    php core/scripts/run-tests.sh --url 'http://localhost:8888/vdc'  --file sites/all/modules/views/lib/Drupal/views/Tests/Style/PluginStyleJumpMenuTest.php
    

    You should get an error like:

    ReflectionException: Class Drupal\views\Tests\Style\PluginStyleJumpMenuTest does not exist in ReflectionClass->__construct() (line 554 of /Applications/MAMP/htdocs/vdc/core/scripts/run-tests.sh).
    
  4. Enable the module and its dependencies and re-run the test. It should now be executed.
  5. Re-disable the module and apply the patch from #52, which rolls back the committed change from #41. The test should now be executed even with the module disabled in the parent environment.
sun’s picture

xjm’s picture

Can we clarify what, exactly, the purpose of the hunk that the patch in #52 reverts is? Steps to test manually?

jthorson’s picture

Status: Needs review » Reviewed & tested by the community

Verified via scratchtestbot that #52 does get the tests running for Views and Ctools, but Chessboard still failed with "Class not found" errors. Core passed during my manual tests as well.

Still, re-enabling testing for 'some' modules is slightly better than the current 'no' modules; so would agree with rolling back the patch in #52 for now, with the caveat that this issue remain open until i) a new patch is provided which addresses the root issue for both core and contrib, or ii) the issues with the Chessboard failures can be explained and attributed to an unrelated issue.

Edit: Chessboard is running and passing, so must have been an issue with my testing environment. Also, based on http://qa.drupal.org/pifr/test/312233, it appears that the abstract classes are being ignored properly ... so retracting the caveats above.

webchick’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks a lot for all of the hard work on the testing. I've committed and pushed #52 to 8.x in order to re-enable contributed module testing. Marking needs work.

I'd also love to know the answer to xjm's queries in #60, since reading through this issue was pretty confusing and I'm still not completely sure what's being fixed here. And, assuming this is fixing a legit bug, it seems like the kind of thing we ought to add test coverage for, if we can.

xjm’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

So:
http://qa.drupal.org/pifr/test/312233

Tests to be run:
 -  (Drupal\broken_tests\Tests\NonAbstractChildTest)
 -  (Drupal\broken_tests\Tests\GetInfolessTest)
 -  (Drupal\broken_tests\Tests\NonAbstractWithMethodChildTest)
 -  (Drupal\broken_tests\Tests\NonAbstractTestBase)
 -  (Drupal\broken_tests\Tests\AbstractWithMethodChildTest)
 -  (Drupal\broken_tests\Tests\AbstractChildTest)
 -  (Drupal\broken_tests\Tests\NonAbstractWithMethodTestBase)

The module includes the following classes:

AbstractChildTest
NonAbstractChildTest
AbstractTestBase
NonAbstractTestBase
AbstractWithMethodChildTest
NonAbstractWithMethodChildTest
AbstractWithMethodTestBase
NonAbstractWithMethodTestBase
GetInfolessTest

As you can see in the results, it attempts to run non-abstract, broken "base" classes NonAbstractWithMethodTestBase and NonAbstractTestBase, as well as all the child classes; however, it does not attempt to run AbstractWithMethodTestBase nor AbstractTestBase. This is with #52 already applied.

So, making base classes abstract (as they should be anyway) resolves the issue as far as I can tell. It did in views.

xjm’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

Oops, xpost (though as mentioned in IRC, I'm not sure that this is testable programmatically).

xjm’s picture

Status: Needs review » Needs work
John_B’s picture

Issue summary: View changes

Note on above syntax examples: for me, back slashes are stripped from class names specified with flag --class unless the class name is enclosed in quotation marks.

sun’s picture

Assigned: sun » Unassigned
Status: Needs work » Fixed
Issue tags: -Needs tests, -Needs backport to D7

This was seemingly fixed a long time ago already. If there's anything that needs a follow-up, let's create a separate issue.

Status: Fixed » Closed (fixed)

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