Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Assertions have less overhead and can be disabled completely, see http://php.net/manual/en/function.assert.php.
Since these methods can be called thousands of times per page load, that's worth it.
Comment | File | Size | Author |
---|---|---|---|
#106 | interdiff.txt | 3.48 KB | dawehner |
#106 | 2454649-106.patch | 34.23 KB | dawehner |
#104 | xhprof runs.zip | 488.47 KB | Wim Leers |
#102 | interdiff.txt | 4.77 KB | Aki Tendo |
#102 | 2454659-102.diff | 33.33 KB | Aki Tendo |
Comments
Comment #1
Aki Tendo CreditAttribution: Aki Tendo commentedI would suggest getting the patch of the referenced ticket in place before starting work with this since it contains code that aids in writing unit tests for classes which can throw assertions, and allows those assertions to be tested cleanly.
Comment #2
Wim LeersSounds reasonable.
Comment #3
Wim LeersComment #4
catchIt'd be useful to have a proof of concept patch here to validate the performance improvement though - and that in turn would help tip the balance towards getting assertion support into 8.0.0 as opposed to a minor release.
Comment #5
Aki Tendo CreditAttribution: Aki Tendo commentedThese patches
https://www.drupal.org/node/2408013#comment-9790657
Implement the goals of this ticket.
Comment #6
Aki Tendo CreditAttribution: Aki Tendo commentedAt Wim's request, working towards removing validateTags(). I'm going to remove the calls to it one patch at a time since the automated testers online run much faster than my local ones (10 minutes vs. nearly an hour and a half).
First test - the call in /Drupal/Core/Cache/ApcuBackend.php at line 169. Also, Changed Cache:: to static:: in the Cache class itself.
Comment #7
Aki Tendo CreditAttribution: Aki Tendo commentedComment #9
Aki Tendo CreditAttribution: Aki Tendo commentedStill can't get local simpletests to work on these patches, even under PHP 5.5, due to previously discovered APCu "feature" (a bug they won't fix). Trying this change, passes PHPUnit.
Drupal\Core\Cache\CacheCollector
Comment #10
Aki Tendo CreditAttribution: Aki Tendo commentedComment #11
Aki Tendo CreditAttribution: Aki Tendo commentedAdding the db backend's call in now - passes PHP Unit without adjustement.
Comment #13
Aki Tendo CreditAttribution: Aki Tendo commentedComment #15
Aki Tendo CreditAttribution: Aki Tendo commentedComment #17
Aki Tendo CreditAttribution: Aki Tendo commentedComment #18
Aki Tendo CreditAttribution: Aki Tendo commentedReady to profile. One profile should be the patch as is, the other with assertions turned off (modify the .htaccess file)
Comment #19
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedAttached is the re-roll of the cache optimizations with the finalized assert tools. I've also hardened the cache library forcing calling classes to obey the interface. (a lot of assert('is_string($cid)') calls). Reassigning this ticket's parent to the assert tools.
Comment #21
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedOne outlying test needed it's context_tags_manager mock updated. There are a couple dozen assert fails from the stronger demands of the new assertions that I need to sort through.
Comment #22
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedComment #23
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedFor the above.
Comment #25
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedLet's see how many assert raises this silences.
Comment #27
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedThe two remaining issues are out of scope for this ticket -- A test that has not been working, and the views module passing bad data to the cache system.
Comment #29
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedIn this patch I've corrected the Alias path test to match current behavior, and then silenced the assertion the views module isn't passing.
Comment #30
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedTest bot wakeup call.
Comment #32
Wim LeersSo close! :)
Comment #33
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedForgot the return validity assertion must also be muted.
Comment #34
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedMoving the failing assertions to the previously created child tickets.
Comment #36
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedRemoving two more assertions that aren't safe until the AliasManager is fixed. They will be placed in that child ticket.
Comment #38
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedChange in assert patch broke the tear down. All should work now.
Comment #39
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commented::kicks the test bot::
Comment #41
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedFailing is_object assertion moved to it's own ticket. This one should now be clear.
Comment #42
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedYay!! Green at last.
Comment #43
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedFunction name change in parent forcing a re-roll.
Comment #45
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedRecently added test needs the cacheContextsManager method defined for the assertion.
Comment #47
Wim Leers#2408013: Adding Assertions to Drupal - Test Tools. just landed, so now we can actually do this! Re-tested #45.
Comment #49
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedAlmost - The tests of this particular group of assertions include checks to see if the assertions are actually firing, and that requires the PHP 7 shim to be finalized.
https://www.drupal.org/node/2536560
That is a much, much smaller issue though.
Comment #50
dawehnerIt is certainly still worth to proceed here ... I wanted to test how much we gain with that. This is just the review only patch rebased against HEAD. Yeah assertions!
Diff%
Diff
(microsec)
Diff%
MemUse
Diff
(bytes)
Diff%
PeakMemUse
Diff
(bytes)
Diff%
Comment #51
Wim LeersYeah, now that #2483433: Optimize CacheableMetadata::merge() + BubbleableMetadata::merge() and #2471232: Optimize Cache::merge*(), by only accepting 2 instead of N arguments have gone in, the gain is bound to be smaller.
Can you describe the test scenario? I'd expected the difference to be bigger.
Comment #52
dawehnerThis was frontpage anonymous without page cache but I would suggest to have some actual stats instead.
Comment #54
dawehnerI hope this fixes some of the problems.
Comment #56
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedPieces of the old assertion patch's traits where being referenced from one of the tests. I think this will run now. Three patches - one is the actual patch, then an interdiff, finally a binding of this patch with #2536560: Runtime Assertion unit and functional testing so that the unit tests can run correctly (some of the tests need to catch \AssertionError )
Comment #57
Wim LeersComment #59
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedRebuild of this patch since so much of the code around it changed.
Comment #60
Wim Leers<3
This should be wrapped in
assert()
.Incomplete docblock.
These messages no longer make sense.
Comment #63
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedI'm beginning to think this new test environment has assert disabled. Rerolling against current and trying again as I cannot duplicate errors locally.
Comment #64
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedComment #66
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedK, I'm going to do these one at a time - starting with just Cache::validateTags(). Wim's code review taken into account on this patch.
Comment #68
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedTest bots are misconfigured.
http://cgit.drupalcode.org/drupalci_testbot/tree/containers/web/web-5.5/...
Current settings:
The semicolon before assert.active needs to be dropped. This explains why the tests are running locally but not online.
Comment #69
mradcliffeI looked on my local drupalci testbot after running the Cache test group.
I then exec'd into the web container and looked at the output of phpinfo. It looks like assert is active in the configuration by default. I'll ping someone in #drupal-testing.
php -i -c /etc/php5/cli/php.ini:
Comment #70
mradcliffeHere's my sqlite file from the Cache testgroup run, which corresponds to the production test bots.
Comment #71
mradcliffeUploaded phpinfo.txt from the container as well.
Edit: that php.ini file i posted in irc was from /etc/php5/cli/php.ini which was wrong according to this phpinfo output. Sorry.
Comment #73
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedForcing assertions to be on (thankfully it's a runtime setting). If this works then the container setting is known to be the culprit.
Comment #74
mradcliffeI tested your patch locally on the testbot, and I still see fails in the Cache group. I think that assertions are active as proven by the phpinfo output I provided, or there is some other hidden setting that needs to be enabled that we are not thinking of.
Attached tarball of my build artifacts from that test run as well.
Edit: Yep, just checked the test run and it's still failing.
Comment #77
mradcliffeThe set function cannot continue if tags has strings. The code is continuing on
PHP on the test runner is configured to **not** bail when assert fails, and that is the default behavior for PHP.
So instead, this is not necessary, but the tests should bail if assert is FALSE?
Comment #79
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedNo. We register an assert callback to throw an AssertionError and that should cause a halt. Is the test running catching the exception, logging it and allowing code flow to continue?
I did find one failure to convert validateTags to an assertion - posting that patch. That *might* be the problem. At this point though I'm looking at my own code even harder trying to find the problem.
Comment #81
mradcliffeStill failing... Do you know where in the chain AssertionError is setup? Maybe KernelTestBase doesn't use Drupal\Component\Assertion\Handle and the exception isn't being handled for PHP5.
I added the PHP7 test. Maybe it will pass under there and that could narrow it down.
Comment #83
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedYeah, registering the handler would help a lot.
Comment #84
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedComment #85
mradcliffeWould it make sense in the grand scheme of using assert() to register the Handler in UnitTestCase? KernelTestBase extends UnitTestCase which extends the generic PHPUnit test class.
Comment #86
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedPossibly - let's see if this is the problem first then deal with that issue over in it's own ticket. The drupal PHPUnit bootstrap calls to register the assert handler at present and I presumed that file would be called for any PHPUnit test. Is that not so?
Note - double calling the handler register function is harmless, but sloppy.
Comment #89
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedNow with monkey patching! (aka a "fix" that cannot be the permanent one, but it will shed light on the nature of the problem and might fix it).
Comment #90
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedComment #93
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedTrying with splicing the registry of assertHandle into TestBase.
Comment #94
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedOk, pass. Should the code adding the assert handle registry to TestBase be spun out to it's own ticket, or is it fine here?
Comment #95
Wim LeersJust one nitpick:
80 cols violation.
This still needs profiling.
But first, I think this should also handle cache context validation: that should be done in an assertion too, there are much bigger gains to be had there. NW for that.
Comment #96
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedOk, fixed the issue above, will appear next patch. Now for cacheContextTag validation.
Comment #97
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedOk, now the CacheContextManager::validateTokens
Comment #98
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedComment #100
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commentedHere we go....
As huge as this looks, it's just adding a mock method with a return of true to cache context mocks wherever they appear in the system.
Comment #101
Wim LeersThis looks great! :)
Pretty much only small stuff below.
s/Tags/tags/
Missing typehint:
string[]
.Missing typehint:
array
.Missing trailing period.
We also generally write
Class::methodName()
, i.e. with parentheses.Also missing leading backslash.
Two spaces, should be one.
Why are we testing this in
CacheTest
, despite the docblock indicating this is testing generic assertion functionality?I don't understand what this is doing.
If we actually need it: please use single quotes instead of double quotes, just for consistency sake.
Comment #102
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commented1. Fixed.
2, 3. The function will accept mixed, but returns FALSE if it isn't an array (first check). Mixed is noted in the @param.
4, 5. Fixed. (Note I forget to hit save and didn't notice until after making the interdiff, so it's missing there. It is in the main patch).
6. This test uses the same data as ::testValidateTags(), which is the previous test. As the docblock says, it's a regression check to insure that the Inspector's assertAllStrings() method will have the same returns as Cache::validateTags() against that data set. I'll admit that it is unusual for the test to be here, but if I moved the test over to the rest of the Inspector tests I'd have to copy over the data provider function as well.
7. I barely understand it. Apparently when writing prophecies you have to state what arguments you should receive in order to pass the test. Each sub array is an argument set that PHPUnit told me it expected but didn't find. It would be cleaner to write it so that any argument would be accepted, but the test is stronger in its current form.
Comment #104
Wim LeersThanks!
I think a committer will find #102.6 insufficiently convincing, but let's see :)
I did some profiling. I created an Article node, with the body field, image field and tags field (3 tags) filled out. I then posted 6 comments. Then I logged in as user 2.
Comment #105
catch#102.6 - yes let's move things over. It's confusing as written, and just moving code to where it belongs should not be confusing once done, even if the patch size gets a bit bigger.
Comment #106
dawehnerSure, let's do that.
Comment #107
Wim Leers+1 for that change.
Comment #108
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRTBC + 1
Comment #110
catchCommitted/pushed to 8.0.x, thanks!
Comment #111
Aki Tendo CreditAttribution: Aki Tendo as a volunteer commented+1 dawehner. Thanks everyone.
Comment #113
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented