Hoo man has uploaded a new change for review. https://gerrit.wikimedia.org/r/305649
Change subject: Make Scribunto_LuaSandboxTests::testArgumentParsingTime more robust ...................................................................... Make Scribunto_LuaSandboxTests::testArgumentParsingTime more robust This should make sure the tests sill work, even if the running node is heavily overloaded. Bug: T143389 Change-Id: Ic40c8d76c8799c2e9d11f53945276747c199fd02 --- M tests/engines/LuaSandbox/SandboxTest.php 1 file changed, 20 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/49/305649/1 diff --git a/tests/engines/LuaSandbox/SandboxTest.php b/tests/engines/LuaSandbox/SandboxTest.php index 6b45403..72f75f3 100644 --- a/tests/engines/LuaSandbox/SandboxTest.php +++ b/tests/engines/LuaSandbox/SandboxTest.php @@ -19,6 +19,11 @@ $this->markTestSkipped( "getrusage is not available" ); } + $getUtime = function() { + $ru = wfGetRusage(); + return $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6; + }; + $engine = $this->getEngine(); if ( !is_callable( array( $engine->getInterpreter()->sandbox, 'pauseUsageTimer' ) ) ) { $this->markTestSkipped( "LuaSandbox::pauseUsageTimer is not available" ); @@ -54,33 +59,45 @@ } '; + // Below we assert that the CPU time counted by LuaSandbox is $delta less than + // the CPU time actually spent. + // That way we can make sure that the time spent in the parser hook (which + // must be more than delta) is not taken into account. + $delta = 0.1; + $u0 = $engine->getInterpreter()->getCPUUsage(); + $uTimeBefore = $getUtime(); $frame->expand( $pp->preprocessToObj( '{{#invoke:TestArgumentParsingTime|f|<scribuntodelay/>}}' ) ); - $this->assertLessThan( 0.25, $engine->getInterpreter()->getCPUUsage() - $u0, + $threshold = $getUtime() - $uTimeBefore - $delta; + $this->assertLessThan( $threshold, $engine->getInterpreter()->getCPUUsage() - $u0, 'Argument access time was not counted' ); + $uTimeBefore = $getUtime(); $u0 = $engine->getInterpreter()->getCPUUsage(); $frame->expand( $pp->preprocessToObj( '{{#invoke:TestArgumentParsingTime|f2|<scribuntodelay/>}}' ) ); - $this->assertLessThan( 0.25, $engine->getInterpreter()->getCPUUsage() - $u0, + $threshold = $getUtime() - $uTimeBefore - $delta; + $this->assertLessThan( $threshold, $engine->getInterpreter()->getCPUUsage() - $u0, 'Unused arguments not counted in preprocess' ); + $uTimeBefore = $getUtime(); $u0 = $engine->getInterpreter()->getCPUUsage(); $frame->expand( $pp->preprocessToObj( '{{#invoke:TestArgumentParsingTime|f3}}' ) ); - $this->assertGreaterThan( 0.25, $engine->getInterpreter()->getCPUUsage() - $u0, + $threshold = $getUtime() - $uTimeBefore - $delta; + $this->assertGreaterThan( $threshold, $engine->getInterpreter()->getCPUUsage() - $u0, 'Recursive argument access time was counted' ); } -- To view, visit https://gerrit.wikimedia.org/r/305649 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic40c8d76c8799c2e9d11f53945276747c199fd02 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits