Since the tests were ported from t/ to phpunit's phase3/maintenance/tests/ in r61938 and other commits running the tests on my machine takes up to 1GB of memory and grows as it runs more tests. It seems that phpunit uses the same instance of the php interpreter for running all the tests.
Is there some way around this? Perhaps phpunit.xml could be tweaked so that it runs a new php for each test?
Furthermore when I run `make test' I get this:
Time: 03:35, Memory: 1849.25Mb
There were 2 failures:
1) LanguageConverterTest::testGetPreferredVariantUserOption Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -tg-latn +tg
/home/avar/src/mw/trunk/phase3/maintenance/tests/LanguageConverterTest.php:82
2) Warning No tests found in class "ParserUnitTest".
FAILURES! Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34
But when I run phpunit manually on the test then all tests pass:
$ phpunit LanguageConverterTest.php PHPUnit 3.4.5 by Sebastian Bergmann.
.........
Time: 23 seconds, Memory: 23.75Mb
OK (9 tests, 34 assertions)
Also after I get "Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34" in the first output phpunit doesn't exit and continues hugging my memory. Why is it still running? It has already run all the tests.
On Wed, Feb 3, 2010 at 17:35, ialex@svn.wikimedia.org wrote:
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/61938
Revision: 61938 Author: ialex Date: 2010-02-03 17:35:59 +0000 (Wed, 03 Feb 2010)
Log Message:
- Port tests from t/inc/
- Added new tests to XmlTest
Added Paths:
trunk/phase3/tests/LicensesTest.php trunk/phase3/tests/SanitizerTest.php trunk/phase3/tests/TimeAdjustTest.php trunk/phase3/tests/TitleTest.php trunk/phase3/tests/XmlTest.php
Added: trunk/phase3/tests/LicensesTest.php
--- trunk/phase3/tests/LicensesTest.php (rev 0) +++ trunk/phase3/tests/LicensesTest.php 2010-02-03 17:35:59 UTC (rev 61938) @@ -0,0 +1,17 @@ +<?php
+/**
- @group Broken
- */
+class LicensesTest extends PHPUnit_Framework_TestCase {
- function testLicenses() {
- $str = "
+* Free licenses: +** GFLD|Debian disagrees +";
- $lc = new Licenses( $str );
- $this->assertTrue( is_a( $lc, 'Licenses' ), 'Correct class' );
- }
+} \ No newline at end of file
Property changes on: trunk/phase3/tests/LicensesTest.php ___________________________________________________________________ Added: svn:eol-style + native
Added: trunk/phase3/tests/SanitizerTest.php
--- trunk/phase3/tests/SanitizerTest.php (rev 0) +++ trunk/phase3/tests/SanitizerTest.php 2010-02-03 17:35:59 UTC (rev 61938) @@ -0,0 +1,71 @@ +<?php
+global $IP; +require_once( "$IP/includes/Sanitizer.php" );
+class SanitizerTest extends PHPUnit_Framework_TestCase {
- function testDecodeNamedEntities() {
- $this->assertEquals(
- "\xc3\xa9cole",
- Sanitizer::decodeCharReferences( 'école' ),
- 'decode named entities'
- );
- }
- function testDecodeNumericEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
- 'decode numeric entities'
- );
- }
- function testDecodeMixedEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ),
- 'decode mixed numeric/named entities'
- );
- }
- function testDecodeMixedComplexEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas Ĉio dans l'école)",
- Sanitizer::decodeCharReferences(
- "Ĉio bonas dans l'école! (mais pas &#x108;io dans l'&eacute;cole)"
- ),
- 'decode mixed complex entities'
- );
- }
- function testInvalidAmpersand() {
- $this->assertEquals(
- 'a & b',
- Sanitizer::decodeCharReferences( 'a & b' ),
- 'Invalid ampersand'
- );
- }
- function testInvalidEntities() {
- $this->assertEquals(
- '&foo;',
- Sanitizer::decodeCharReferences( '&foo;' ),
- 'Invalid named entity'
- );
- }
- function testInvalidNumberedEntities() {
- $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "�" ), 'Invalid numbered entity' );
- }
- function testSelfClosingTag() {
- $GLOBALS['wgUseTidy'] = false;
- $this->assertEquals(
- '<div>Hello world</div>',
- Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
- 'Self-closing closing div'
- );
- }
+}
Property changes on: trunk/phase3/tests/SanitizerTest.php ___________________________________________________________________ Added: svn:eol-style + native
Added: trunk/phase3/tests/TimeAdjustTest.php
--- trunk/phase3/tests/TimeAdjustTest.php (rev 0) +++ trunk/phase3/tests/TimeAdjustTest.php 2010-02-03 17:35:59 UTC (rev 61938) @@ -0,0 +1,40 @@ +<?php
+class TimeAdjustTest extends PHPUnit_Framework_TestCase {
- public function setUp() {
- $this->iniSet( 'precision', 15 );
- }
- # Test offset usage for a given language::userAdjust
- function testUserAdjust() {
- global $wgLocalTZoffset, $wgContLang, $wgUser;
- $wgContLang = $en = Language::factory( 'en' );
- # Collection of parameters for Language_t_Offset.
- # Format: date to be formatted, localTZoffset value, expected date
- $userAdjust_tests = array(
- array( 20061231235959, 0, 20061231235959 ),
- array( 20061231235959, 5, 20070101000459 ),
- array( 20061231235959, 15, 20070101001459 ),
- array( 20061231235959, 60, 20070101005959 ),
- array( 20061231235959, 90, 20070101012959 ),
- array( 20061231235959, 120, 20070101015959 ),
- array( 20061231235959, 540, 20070101085959 ),
- array( 20061231235959, -5, 20061231235459 ),
- array( 20061231235959, -30, 20061231232959 ),
- array( 20061231235959, -60, 20061231225959 ),
- );
- foreach( $userAdjust_tests as $data ) {
- $wgLocalTZoffset = $data[1];
- $this->assertEquals(
- strval( $data[2] ),
- strval( $en->userAdjust( $data[0], '' ) ),
- "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
- );
- }
- }
+}
Property changes on: trunk/phase3/tests/TimeAdjustTest.php ___________________________________________________________________ Added: svn:eol-style + native
Added: trunk/phase3/tests/TitleTest.php
--- trunk/phase3/tests/TitleTest.php (rev 0) +++ trunk/phase3/tests/TitleTest.php 2010-02-03 17:35:59 UTC (rev 61938) @@ -0,0 +1,17 @@ +<?php
+class TitleTest extends PHPUnit_Framework_TestCase {
- function testLegalChars() {
- $titlechars = Title::legalChars();
- foreach ( range( 1, 255 ) as $num ) {
- $chr = chr( $num );
- if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\x00-\x1f\x7f]/", $chr ) ) {
- $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
- } else {
- $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
- }
- }
- }
+}
Property changes on: trunk/phase3/tests/TitleTest.php ___________________________________________________________________ Added: svn:eol-style + native
Added: trunk/phase3/tests/XmlTest.php
--- trunk/phase3/tests/XmlTest.php (rev 0) +++ trunk/phase3/tests/XmlTest.php 2010-02-03 17:35:59 UTC (rev 61938) @@ -0,0 +1,115 @@ +<?php
+class XmlTest extends PHPUnit_Framework_TestCase {
- function testElementOpen() {
- $this->assertEquals(
- '<element>',
- Xml::element( 'element', null, null ),
- 'Opening element with no attributes'
- );
- }
- function testElementEmpty() {
- $this->assertEquals(
- '<element />',
- Xml::element( 'element', null, '' ),
- 'Terminated empty element'
- );
- }
- function testElementEscaping() {
- $this->assertEquals(
- '<element>hello <there> you & you</element>',
- Xml::element( 'element', null, 'hello <there> you & you' ),
- 'Element with no attributes and content that needs escaping'
- );
- }
- function testElementAttributes() {
- $this->assertEquals(
- '<element key="value" <>="<>">',
- Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
- 'Element attributes, keys are not escaped'
- );
- }
- function testOpenElement() {
- $this->assertEquals(
- '<element k="v">',
- Xml::openElement( 'element', array( 'k' => 'v' ) ),
- 'openElement() shortcut'
- );
- }
- function testCloseElement() {
- $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
- }
- #
- # textarea
- #
- function testTextareaNoContent() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
- Xml::textarea( 'name', '' ),
- 'textarea() with not content'
- );
- }
- function testTextareaAttribs() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>',
- Xml::textarea( 'name', '<txt>', 20, 10 ),
- 'textarea() with custom attribs'
- );
- }
- #
- # JS
- #
- function testEscapeJsStringSpecialChars() {
- $this->assertEquals(
- '\\\r\n',
- Xml::escapeJsString( "\\r\n" ),
- 'escapeJsString() with special characters'
- );
- }
- function testEncodeJsVarBoolean() {
- $this->assertEquals(
- 'true',
- Xml::encodeJsVar( true ),
- 'encodeJsVar() with boolean'
- );
- }
- function testEncodeJsVarNull() {
- $this->assertEquals(
- 'null',
- Xml::encodeJsVar( null ),
- 'encodeJsVar() with null'
- );
- }
- function testEncodeJsVarArray() {
- $this->assertEquals(
- '["a", 1]',
- Xml::encodeJsVar( array( 'a', 1 ) ),
- 'encodeJsVar() with array'
- );
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
- 'encodeJsVar() with associative array'
- );
- }
- function testEncodeJsVarObject() {
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
- 'encodeJsVar() with object'
- );
- }
+}
Property changes on: trunk/phase3/tests/XmlTest.php ___________________________________________________________________ Added: svn:eol-style + native
MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
A guess would be to try PHP 5.3, and enable the garbage collector.
http://www.php.net/manual/en/function.gc-enable.php
Jared
-----Original Message----- From: wikitech-l-bounces@lists.wikimedia.org [mailto:wikitech-l-bounces@lists.wikimedia.org] On Behalf Of Ævar Arnfjörð Bjarmason Sent: 06 February 2010 01:05 To: wikitech-l@lists.wikimedia.org Cc: mediawiki-cvs@lists.wikimedia.org Subject: [Wikitech-l] New phpunit tests eat ~1GB of memory
Since the tests were ported from t/ to phpunit's phase3/maintenance/tests/ in r61938 and other commits running the tests on my machine takes up to 1GB of memory and grows as it runs more tests. It seems that phpunit uses the same instance of the php interpreter for running all the tests.
Is there some way around this? Perhaps phpunit.xml could be tweaked so that it runs a new php for each test?
Furthermore when I run `make test' I get this:
Time: 03:35, Memory: 1849.25Mb There were 2 failures: 1) LanguageConverterTest::testGetPreferredVariantUserOption Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -tg-latn +tg
/home/avar/src/mw/trunk/phase3/maintenance/tests/LanguageConve rterTest.php:82
2) Warning No tests found in class "ParserUnitTest". FAILURES! Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34
But when I run phpunit manually on the test then all tests pass:
$ phpunit LanguageConverterTest.php PHPUnit 3.4.5 by Sebastian Bergmann. ......... Time: 23 seconds, Memory: 23.75Mb OK (9 tests, 34 assertions)
Also after I get "Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34" in the first output phpunit doesn't exit and continues hugging my memory. Why is it still running? It has already run all the tests.
On Wed, Feb 3, 2010 at 17:35, ialex@svn.wikimedia.org wrote:
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/61938
Revision: 61938 Author: ialex Date: 2010-02-03 17:35:59 +0000 (Wed, 03 Feb 2010)
Log Message:
- Port tests from t/inc/
- Added new tests to XmlTest
Added Paths:
trunk/phase3/tests/LicensesTest.php trunk/phase3/tests/SanitizerTest.php trunk/phase3/tests/TimeAdjustTest.php trunk/phase3/tests/TitleTest.php trunk/phase3/tests/XmlTest.php
Added: trunk/phase3/tests/LicensesTest.php
===================================================================
--- trunk/phase3/tests/LicensesTest.php
(rev
+++ trunk/phase3/tests/LicensesTest.php 2010-02-03 17:35:59
UTC (rev
+++ 61938) @@ -0,0 +1,17 @@ +<?php
+/**
- @group Broken
- */
+class LicensesTest extends PHPUnit_Framework_TestCase {
- function testLicenses() {
- $str = "
+* Free licenses: +** GFLD|Debian disagrees +";
- $lc = new Licenses( $str );
- $this->assertTrue( is_a( $lc, 'Licenses' ),
'Correct
+class' );
- }
+} \ No newline at end of file
Property changes on: trunk/phase3/tests/LicensesTest.php
___________________________________________________________________
Added: svn:eol-style + native
Added: trunk/phase3/tests/SanitizerTest.php
===================================================================
--- trunk/phase3/tests/SanitizerTest.php
(rev 0) +++ trunk/phase3/tests/SanitizerTest.php 2010-02-03
17:35:59
+++ UTC (rev 61938) @@ -0,0 +1,71 @@ +<?php
+global $IP; +require_once( "$IP/includes/Sanitizer.php" );
+class SanitizerTest extends PHPUnit_Framework_TestCase {
- function testDecodeNamedEntities() {
- $this->assertEquals(
- "\xc3\xa9cole",
- Sanitizer::decodeCharReferences(
- 'école' ),
- 'decode named entities'
- );
- }
- function testDecodeNumericEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences(
"Ĉio
- bonas dans l'école!" ),
- 'decode numeric entities'
- );
- }
- function testDecodeMixedEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences(
"Ĉio
- bonas dans l'école!" ),
- 'decode mixed numeric/named entities'
- );
- }
- function testDecodeMixedComplexEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans
l'\xc3\xa9cole! (mais
- pas Ĉio dans l'école)",
- Sanitizer::decodeCharReferences(
- "Ĉio bonas dans
l'école! (mais pas &#x108;io dans l'&eacute;cole)"
- ),
- 'decode mixed complex entities'
- );
- }
- function testInvalidAmpersand() {
- $this->assertEquals(
- 'a & b',
- Sanitizer::decodeCharReferences( 'a & b'
),
- 'Invalid ampersand'
- );
- }
- function testInvalidEntities() {
- $this->assertEquals(
- '&foo;',
- Sanitizer::decodeCharReferences( '&foo;'
),
- 'Invalid named entity'
- );
- }
- function testInvalidNumberedEntities() {
- $this->assertEquals( UTF8_REPLACEMENT,
- Sanitizer::decodeCharReferences( "�" ), 'Invalid
- numbered entity' );
- }
- function testSelfClosingTag() {
- $GLOBALS['wgUseTidy'] = false;
- $this->assertEquals(
- '<div>Hello world</div>',
- Sanitizer::removeHTMLtags( '<div>Hello
+world</div />' ),
- 'Self-closing closing div'
- );
- }
+}
Property changes on: trunk/phase3/tests/SanitizerTest.php
___________________________________________________________________
Added: svn:eol-style + native
Added: trunk/phase3/tests/TimeAdjustTest.php
===================================================================
--- trunk/phase3/tests/TimeAdjustTest.php
(rev 0) +++ trunk/phase3/tests/TimeAdjustTest.php 2010-02-03
17:35:59
+++ UTC (rev 61938) @@ -0,0 +1,40 @@ +<?php
+class TimeAdjustTest extends PHPUnit_Framework_TestCase {
- public function setUp() {
- $this->iniSet( 'precision', 15 );
- }
- # Test offset usage for a given language::userAdjust
- function testUserAdjust() {
- global $wgLocalTZoffset, $wgContLang, $wgUser;
- $wgContLang = $en = Language::factory( 'en' );
- # Collection of parameters for Language_t_Offset.
- # Format: date to be formatted,
localTZoffset value,
- expected date
- $userAdjust_tests = array(
- array( 20061231235959, 0,
20061231235959 ),
- array( 20061231235959, 5,
20070101000459 ),
- array( 20061231235959, 15,
20070101001459 ),
- array( 20061231235959, 60,
20070101005959 ),
- array( 20061231235959, 90,
20070101012959 ),
- array( 20061231235959, 120,
20070101015959 ),
- array( 20061231235959, 540,
20070101085959 ),
- array( 20061231235959, -5,
20061231235459 ),
- array( 20061231235959, -30,
20061231232959 ),
- array( 20061231235959, -60,
20061231225959 ),
- );
- foreach( $userAdjust_tests as $data ) {
- $wgLocalTZoffset = $data[1];
- $this->assertEquals(
- strval( $data[2] ),
- strval( $en->userAdjust(
$data[0], ''
+) ),
- "User adjust {$data[0]} by
{$data[1]} minutes should give {$data[2]}"
- );
- }
- }
+}
Property changes on: trunk/phase3/tests/TimeAdjustTest.php
___________________________________________________________________
Added: svn:eol-style + native
Added: trunk/phase3/tests/TitleTest.php
===================================================================
--- trunk/phase3/tests/TitleTest.php
(rev
+++ trunk/phase3/tests/TitleTest.php 2010-02-03 17:35:59
UTC (rev
+++ 61938) @@ -0,0 +1,17 @@ +<?php
+class TitleTest extends PHPUnit_Framework_TestCase {
- function testLegalChars() {
- $titlechars = Title::legalChars();
- foreach ( range( 1, 255 ) as $num ) {
- $chr = chr( $num );
- if ( strpos( "#[]{}<>|", $chr ) !==
false ||
+preg_match( "/[\x00-\x1f\x7f]/", $chr ) ) {
- $this->assertFalse(
(bool)preg_match(
+"/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid +titlechar" );
- } else {
- $this->assertTrue(
(bool)preg_match(
+"/[$titlechars]/", $chr ), "chr($num) = $chr is a valid
titlechar" );
- }
- }
- }
+}
Property changes on: trunk/phase3/tests/TitleTest.php
___________________________________________________________________
Added: svn:eol-style + native
Added: trunk/phase3/tests/XmlTest.php
===================================================================
--- trunk/phase3/tests/XmlTest.php
(rev
+++ trunk/phase3/tests/XmlTest.php 2010-02-03 17:35:59
UTC (rev
+++ 61938) @@ -0,0 +1,115 @@ +<?php
+class XmlTest extends PHPUnit_Framework_TestCase {
- function testElementOpen() {
- $this->assertEquals(
- '<element>',
- Xml::element( 'element', null, null ),
- 'Opening element with no attributes'
- );
- }
- function testElementEmpty() {
- $this->assertEquals(
- '<element />',
- Xml::element( 'element', null, '' ),
- 'Terminated empty element'
- );
- }
- function testElementEscaping() {
- $this->assertEquals(
- '<element>hello <there> you &
- you</element>',
- Xml::element( 'element', null,
'hello <there>
- you & you' ),
- 'Element with no attributes and
content that needs escaping'
- );
- }
- function testElementAttributes() {
- $this->assertEquals(
- '<element key="value" <>="<>">',
- Xml::element( 'element', array( 'key' =>
- 'value', '<>' => '<>' ), null ),
- 'Element attributes, keys are not escaped'
- );
- }
- function testOpenElement() {
- $this->assertEquals(
- '<element k="v">',
- Xml::openElement( 'element', array(
'k' => 'v'
- ) ),
- 'openElement() shortcut'
- );
- }
- function testCloseElement() {
- $this->assertEquals( '</element>',
Xml::closeElement(
- 'element' ), 'closeElement() shortcut' );
- }
- #
- # textarea
- #
- function testTextareaNoContent() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="40"
- rows="5"></textarea>',
- Xml::textarea( 'name', '' ),
- 'textarea() with not content'
- );
- }
- function testTextareaAttribs() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="20"
- rows="10"><txt></textarea>',
- Xml::textarea( 'name', '<txt>', 20, 10 ),
- 'textarea() with custom attribs'
- );
- }
- #
- # JS
- #
- function testEscapeJsStringSpecialChars() {
- $this->assertEquals(
- '\\\r\n',
- Xml::escapeJsString( "\\r\n" ),
- 'escapeJsString() with special characters'
- );
- }
- function testEncodeJsVarBoolean() {
- $this->assertEquals(
- 'true',
- Xml::encodeJsVar( true ),
- 'encodeJsVar() with boolean'
- );
- }
- function testEncodeJsVarNull() {
- $this->assertEquals(
- 'null',
- Xml::encodeJsVar( null ),
- 'encodeJsVar() with null'
- );
- }
- function testEncodeJsVarArray() {
- $this->assertEquals(
- '["a", 1]',
- Xml::encodeJsVar( array( 'a', 1 ) ),
- 'encodeJsVar() with array'
- );
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( array( 'a' =>
'a', 'b' => 1
- ) ),
- 'encodeJsVar() with associative array'
- );
- }
- function testEncodeJsVarObject() {
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( (object)array(
'a' => 'a',
+'b' => 1 ) ),
- 'encodeJsVar() with object'
- );
- }
+}
Property changes on: trunk/phase3/tests/XmlTest.php
___________________________________________________________________
Added: svn:eol-style + native
MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
off-topic-ish
theres also a function to explicit call the collector (sorry, I forgot the name)
it seems php only flag things for collecting (wen you unset($stuff) ), but never really collect then. The documentation says that the collector will run wen theres not work to do, but this seems a very rare event (maybe is never triggered).
hu,,
On 6 February 2010 03:37, Jared Williams jared.williams1@ntlworld.com wrote:
A guess would be to try PHP 5.3, and enable the garbage collector.
http://www.php.net/manual/en/function.gc-enable.php
Jared
-----Original Message----- From: wikitech-l-bounces@lists.wikimedia.org [mailto:wikitech-l-bounces@lists.wikimedia.org] On Behalf Of Ævar Arnfjörð Bjarmason Sent: 06 February 2010 01:05 To: wikitech-l@lists.wikimedia.org Cc: mediawiki-cvs@lists.wikimedia.org Subject: [Wikitech-l] New phpunit tests eat ~1GB of memory
Since the tests were ported from t/ to phpunit's phase3/maintenance/tests/ in r61938 and other commits running the tests on my machine takes up to 1GB of memory and grows as it runs more tests. It seems that phpunit uses the same instance of the php interpreter for running all the tests.
Is there some way around this? Perhaps phpunit.xml could be tweaked so that it runs a new php for each test?
Furthermore when I run `make test' I get this:
Time: 03:35, Memory: 1849.25Mb
There were 2 failures:
1) LanguageConverterTest::testGetPreferredVariantUserOption Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -tg-latn +tg
/home/avar/src/mw/trunk/phase3/maintenance/tests/LanguageConve rterTest.php:82
2) Warning No tests found in class "ParserUnitTest".
FAILURES! Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34
But when I run phpunit manually on the test then all tests pass:
$ phpunit LanguageConverterTest.php PHPUnit 3.4.5 by Sebastian Bergmann.
.........
Time: 23 seconds, Memory: 23.75Mb
OK (9 tests, 34 assertions)
Also after I get "Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34" in the first output phpunit doesn't exit and continues hugging my memory. Why is it still running? It has already run all the tests.
On Wed, Feb 3, 2010 at 17:35, ialex@svn.wikimedia.org wrote:
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/61938
Revision: 61938 Author: ialex Date: 2010-02-03 17:35:59 +0000 (Wed, 03 Feb 2010)
Log Message:
- Port tests from t/inc/
- Added new tests to XmlTest
Added Paths:
trunk/phase3/tests/LicensesTest.php trunk/phase3/tests/SanitizerTest.php trunk/phase3/tests/TimeAdjustTest.php trunk/phase3/tests/TitleTest.php trunk/phase3/tests/XmlTest.php
Added: trunk/phase3/tests/LicensesTest.php
===================================================================
--- trunk/phase3/tests/LicensesTest.php
(rev
+++ trunk/phase3/tests/LicensesTest.php 2010-02-03 17:35:59
UTC (rev
+++ 61938) @@ -0,0 +1,17 @@ +<?php
+/**
- @group Broken
- */
+class LicensesTest extends PHPUnit_Framework_TestCase {
- function testLicenses() {
- $str = "
+* Free licenses: +** GFLD|Debian disagrees +";
- $lc = new Licenses( $str );
- $this->assertTrue( is_a( $lc, 'Licenses' ),
'Correct
+class' );
- }
+} \ No newline at end of file
Property changes on: trunk/phase3/tests/LicensesTest.php
Added: svn:eol-style + native
Added: trunk/phase3/tests/SanitizerTest.php
===================================================================
--- trunk/phase3/tests/SanitizerTest.php
(rev 0) +++ trunk/phase3/tests/SanitizerTest.php 2010-02-03
17:35:59
+++ UTC (rev 61938) @@ -0,0 +1,71 @@ +<?php
+global $IP; +require_once( "$IP/includes/Sanitizer.php" );
+class SanitizerTest extends PHPUnit_Framework_TestCase {
- function testDecodeNamedEntities() {
- $this->assertEquals(
- "\xc3\xa9cole",
- Sanitizer::decodeCharReferences(
- 'école' ),
- 'decode named entities'
- );
- }
- function testDecodeNumericEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences(
"Ĉio
- bonas dans l'école!" ),
- 'decode numeric entities'
- );
- }
- function testDecodeMixedEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans l'\xc3\xa9cole!",
- Sanitizer::decodeCharReferences(
"Ĉio
- bonas dans l'école!" ),
- 'decode mixed numeric/named entities'
- );
- }
- function testDecodeMixedComplexEntities() {
- $this->assertEquals(
- "\xc4\x88io bonas dans
l'\xc3\xa9cole! (mais
- pas Ĉio dans l'école)",
- Sanitizer::decodeCharReferences(
- "Ĉio bonas dans
l'école! (mais pas &#x108;io dans l'&eacute;cole)"
- ),
- 'decode mixed complex entities'
- );
- }
- function testInvalidAmpersand() {
- $this->assertEquals(
- 'a & b',
- Sanitizer::decodeCharReferences( 'a & b'
),
- 'Invalid ampersand'
- );
- }
- function testInvalidEntities() {
- $this->assertEquals(
- '&foo;',
- Sanitizer::decodeCharReferences( '&foo;'
),
- 'Invalid named entity'
- );
- }
- function testInvalidNumberedEntities() {
- $this->assertEquals( UTF8_REPLACEMENT,
- Sanitizer::decodeCharReferences( "�" ), 'Invalid
- numbered entity' );
- }
- function testSelfClosingTag() {
- $GLOBALS['wgUseTidy'] = false;
- $this->assertEquals(
- '<div>Hello world</div>',
- Sanitizer::removeHTMLtags( '<div>Hello
+world</div />' ),
- 'Self-closing closing div'
- );
- }
+}
Property changes on: trunk/phase3/tests/SanitizerTest.php
Added: svn:eol-style + native
Added: trunk/phase3/tests/TimeAdjustTest.php
===================================================================
--- trunk/phase3/tests/TimeAdjustTest.php
(rev 0) +++ trunk/phase3/tests/TimeAdjustTest.php 2010-02-03
17:35:59
+++ UTC (rev 61938) @@ -0,0 +1,40 @@ +<?php
+class TimeAdjustTest extends PHPUnit_Framework_TestCase {
- public function setUp() {
- $this->iniSet( 'precision', 15 );
- }
- # Test offset usage for a given language::userAdjust
- function testUserAdjust() {
- global $wgLocalTZoffset, $wgContLang, $wgUser;
- $wgContLang = $en = Language::factory( 'en' );
- # Collection of parameters for Language_t_Offset.
- # Format: date to be formatted,
localTZoffset value,
- expected date
- $userAdjust_tests = array(
- array( 20061231235959, 0,
20061231235959 ),
- array( 20061231235959, 5,
20070101000459 ),
- array( 20061231235959, 15,
20070101001459 ),
- array( 20061231235959, 60,
20070101005959 ),
- array( 20061231235959, 90,
20070101012959 ),
- array( 20061231235959, 120,
20070101015959 ),
- array( 20061231235959, 540,
20070101085959 ),
- array( 20061231235959, -5,
20061231235459 ),
- array( 20061231235959, -30,
20061231232959 ),
- array( 20061231235959, -60,
20061231225959 ),
- );
- foreach( $userAdjust_tests as $data ) {
- $wgLocalTZoffset = $data[1];
- $this->assertEquals(
- strval( $data[2] ),
- strval( $en->userAdjust(
$data[0], ''
+) ),
- "User adjust {$data[0]} by
{$data[1]} minutes should give {$data[2]}"
- );
- }
- }
+}
Property changes on: trunk/phase3/tests/TimeAdjustTest.php
Added: svn:eol-style + native
Added: trunk/phase3/tests/TitleTest.php
===================================================================
--- trunk/phase3/tests/TitleTest.php
(rev
+++ trunk/phase3/tests/TitleTest.php 2010-02-03 17:35:59
UTC (rev
+++ 61938) @@ -0,0 +1,17 @@ +<?php
+class TitleTest extends PHPUnit_Framework_TestCase {
- function testLegalChars() {
- $titlechars = Title::legalChars();
- foreach ( range( 1, 255 ) as $num ) {
- $chr = chr( $num );
- if ( strpos( "#[]{}<>|", $chr ) !==
false ||
+preg_match( "/[\x00-\x1f\x7f]/", $chr ) ) {
- $this->assertFalse(
(bool)preg_match(
+"/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid +titlechar" );
- } else {
- $this->assertTrue(
(bool)preg_match(
+"/[$titlechars]/", $chr ), "chr($num) = $chr is a valid
titlechar" );
- }
- }
- }
+}
Property changes on: trunk/phase3/tests/TitleTest.php
Added: svn:eol-style + native
Added: trunk/phase3/tests/XmlTest.php
===================================================================
--- trunk/phase3/tests/XmlTest.php
(rev
+++ trunk/phase3/tests/XmlTest.php 2010-02-03 17:35:59
UTC (rev
+++ 61938) @@ -0,0 +1,115 @@ +<?php
+class XmlTest extends PHPUnit_Framework_TestCase {
- function testElementOpen() {
- $this->assertEquals(
- '<element>',
- Xml::element( 'element', null, null ),
- 'Opening element with no attributes'
- );
- }
- function testElementEmpty() {
- $this->assertEquals(
- '<element />',
- Xml::element( 'element', null, '' ),
- 'Terminated empty element'
- );
- }
- function testElementEscaping() {
- $this->assertEquals(
- '<element>hello <there> you &
- you</element>',
- Xml::element( 'element', null,
'hello <there>
- you & you' ),
- 'Element with no attributes and
content that needs escaping'
- );
- }
- function testElementAttributes() {
- $this->assertEquals(
- '<element key="value" <>="<>">',
- Xml::element( 'element', array( 'key' =>
- 'value', '<>' => '<>' ), null ),
- 'Element attributes, keys are not escaped'
- );
- }
- function testOpenElement() {
- $this->assertEquals(
- '<element k="v">',
- Xml::openElement( 'element', array(
'k' => 'v'
- ) ),
- 'openElement() shortcut'
- );
- }
- function testCloseElement() {
- $this->assertEquals( '</element>',
Xml::closeElement(
- 'element' ), 'closeElement() shortcut' );
- }
- #
- # textarea
- #
- function testTextareaNoContent() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="40"
- rows="5"></textarea>',
- Xml::textarea( 'name', '' ),
- 'textarea() with not content'
- );
- }
- function testTextareaAttribs() {
- $this->assertEquals(
- '<textarea name="name" id="name" cols="20"
- rows="10"><txt></textarea>',
- Xml::textarea( 'name', '<txt>', 20, 10 ),
- 'textarea() with custom attribs'
- );
- }
- #
- # JS
- #
- function testEscapeJsStringSpecialChars() {
- $this->assertEquals(
- '\\\r\n',
- Xml::escapeJsString( "\\r\n" ),
- 'escapeJsString() with special characters'
- );
- }
- function testEncodeJsVarBoolean() {
- $this->assertEquals(
- 'true',
- Xml::encodeJsVar( true ),
- 'encodeJsVar() with boolean'
- );
- }
- function testEncodeJsVarNull() {
- $this->assertEquals(
- 'null',
- Xml::encodeJsVar( null ),
- 'encodeJsVar() with null'
- );
- }
- function testEncodeJsVarArray() {
- $this->assertEquals(
- '["a", 1]',
- Xml::encodeJsVar( array( 'a', 1 ) ),
- 'encodeJsVar() with array'
- );
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( array( 'a' =>
'a', 'b' => 1
- ) ),
- 'encodeJsVar() with associative array'
- );
- }
- function testEncodeJsVarObject() {
- $this->assertEquals(
- '{"a": "a", "b": 1}',
- Xml::encodeJsVar( (object)array(
'a' => 'a',
+'b' => 1 ) ),
- 'encodeJsVar() with object'
- );
- }
+}
Property changes on: trunk/phase3/tests/XmlTest.php
Added: svn:eol-style + native
MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Sat, Feb 6, 2010 at 01:04, Ævar Arnfjörð Bjarmason avarab@gmail.com wrote:
Since the tests were ported from t/ to phpunit's phase3/maintenance/tests/ in r61938 and other commits running the tests on my machine takes up to 1GB of memory and grows as it runs more tests. It seems that phpunit uses the same instance of the php interpreter for running all the tests.
Is there some way around this? Perhaps phpunit.xml could be tweaked so that it runs a new php for each test?
Furthermore when I run `make test' I get this:
Time: 03:35, Memory: 1849.25Mb
There were 2 failures:
1) LanguageConverterTest::testGetPreferredVariantUserOption Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -tg-latn +tg
/home/avar/src/mw/trunk/phase3/maintenance/tests/LanguageConverterTest.php:82
2) Warning No tests found in class "ParserUnitTest".
FAILURES! Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34
But when I run phpunit manually on the test then all tests pass:
$ phpunit LanguageConverterTest.php PHPUnit 3.4.5 by Sebastian Bergmann.
.........
Time: 23 seconds, Memory: 23.75Mb
OK (9 tests, 34 assertions)
Also after I get "Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34" in the first output phpunit doesn't exit and continues hugging my memory. Why is it still running? It has already run all the tests.
I've worked around this by adding a 'make tap' target which runs the phpunit tests individually with Test::Harness. I made it the default target due to the problems with running all the tests at once with phpunit:
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62071 http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62072
Does something run these tests or the parsertests automatically? It would be really neat to test all svn revisions of MediaWiki and report the results on Special:Code. I think I read somewhere that something runs the parsertests automatically.
On Sat, Feb 6, 2010 at 11:24 AM, Ævar Arnfjörð Bjarmason avarab@gmail.com wrote:
On Sat, Feb 6, 2010 at 01:04, Ævar Arnfjörð Bjarmason avarab@gmail.com wrote:
Since the tests were ported from t/ to phpunit's phase3/maintenance/tests/ in r61938 and other commits running the tests on my machine takes up to 1GB of memory and grows as it runs more tests. It seems that phpunit uses the same instance of the php interpreter for running all the tests.
Is there some way around this? Perhaps phpunit.xml could be tweaked so that it runs a new php for each test?
Furthermore when I run `make test' I get this:
Time: 03:35, Memory: 1849.25Mb
There were 2 failures:
1) LanguageConverterTest::testGetPreferredVariantUserOption Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -tg-latn +tg
/home/avar/src/mw/trunk/phase3/maintenance/tests/LanguageConverterTest.php:82
2) Warning No tests found in class "ParserUnitTest".
FAILURES! Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34
But when I run phpunit manually on the test then all tests pass:
$ phpunit LanguageConverterTest.php PHPUnit 3.4.5 by Sebastian Bergmann.
.........
Time: 23 seconds, Memory: 23.75Mb
OK (9 tests, 34 assertions)
Also after I get "Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34" in the first output phpunit doesn't exit and continues hugging my memory. Why is it still running? It has already run all the tests.
I've worked around this by adding a 'make tap' target which runs the phpunit tests individually with Test::Harness. I made it the default target due to the problems with running all the tests at once with phpunit:
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62071 http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62072
Does something run these tests or the parsertests automatically? It would be really neat to test all svn revisions of MediaWiki and report the results on Special:Code. I think I read somewhere that something runs the parsertests automatically.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
It's supposed to be running the parser tests and uploading them on commit, but that's been broken for a little while now. If we're got a nice standard output from the tests (I think the XML is pretty suited for this), we should be able to upload that result to Code Review.
-Chad
On Sat, Feb 6, 2010 at 16:27, Chad innocentkiller@gmail.com wrote:
On Sat, Feb 6, 2010 at 11:24 AM, Ævar Arnfjörð Bjarmason avarab@gmail.com wrote:
On Sat, Feb 6, 2010 at 01:04, Ævar Arnfjörð Bjarmason avarab@gmail.com wrote:
Since the tests were ported from t/ to phpunit's phase3/maintenance/tests/ in r61938 and other commits running the tests on my machine takes up to 1GB of memory and grows as it runs more tests. It seems that phpunit uses the same instance of the php interpreter for running all the tests.
Is there some way around this? Perhaps phpunit.xml could be tweaked so that it runs a new php for each test?
Furthermore when I run `make test' I get this:
Time: 03:35, Memory: 1849.25Mb
There were 2 failures:
1) LanguageConverterTest::testGetPreferredVariantUserOption Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -tg-latn +tg
/home/avar/src/mw/trunk/phase3/maintenance/tests/LanguageConverterTest.php:82
2) Warning No tests found in class "ParserUnitTest".
FAILURES! Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34
But when I run phpunit manually on the test then all tests pass:
$ phpunit LanguageConverterTest.php PHPUnit 3.4.5 by Sebastian Bergmann.
.........
Time: 23 seconds, Memory: 23.75Mb
OK (9 tests, 34 assertions)
Also after I get "Tests: 686, Assertions: 3431, Failures: 2, Incomplete: 34" in the first output phpunit doesn't exit and continues hugging my memory. Why is it still running? It has already run all the tests.
I've worked around this by adding a 'make tap' target which runs the phpunit tests individually with Test::Harness. I made it the default target due to the problems with running all the tests at once with phpunit:
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62071 http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62072
Does something run these tests or the parsertests automatically? It would be really neat to test all svn revisions of MediaWiki and report the results on Special:Code. I think I read somewhere that something runs the parsertests automatically.
It's supposed to be running the parser tests and uploading them on commit, but that's been broken for a little while now.
What system is this that's running automatic tests on commits? I was investigating setting up a buildbot (http://buildbot.net/) which could have multiple test clients and report tests to IRC/XML which Special:Code could then use.
What does the now-broken Special:Code test system use?
If we're got a nice standard output from the tests (I think the XML is pretty suited for this), we should be able to upload that result to Code Review.
$ prove -j 10 -e 'phpunit --tap' -Q *Test*.php All tests successful. Files=20, Tests=692, 31 wallclock secs ( 0.34 usr 0.21 sys + 18443939634.30 cusr 2803481.20 csys = 18446743116.05 CPU) Result: PASS
You can get pretty HTML like this:
$ prove --formatter TAP::Formatter::HTML -j 10 -e 'phpunit --tap' -Q *Test*.php > ~/www/mw-tap-out.html
Which gives you something like this:
http://v.nix.is/~avar/mw-tap-out.html
That can be parsed with any XML parser that just has to look for <td class="results"> and <div id="summary" class="passed"> or <div id="summary" class="failed">
wikitech-l@lists.wikimedia.org