Speed up ApiQuerySiteinfoTest:testContinuation
authorAntoine Musso <hashar@free.fr>
Fri, 27 Sep 2019 08:42:56 +0000 (10:42 +0200)
committerAntoine Musso <hashar@free.fr>
Fri, 27 Sep 2019 08:42:56 +0000 (10:42 +0200)
The test fills $wgUrlProtocols with 86000 entries, forging oversized
strings which ends up eventually truncated to 100 bytes.  The aim is to
overflow $wgAPIMaxResultSize to trigger an apiwarn-truncatedresult
warning.

The test takes 230 ms on my machine and when generating code coverage
almost a minute.

A faster approach is just to lower the $wgAPIMaxResultSize limit to
trigger the warning.

Test plan:

  $ php tests/phpunit/phpunit.php \
      tests/phpunit/includes/api/ApiQuerySiteinfoTest.php \
      --filter testContinuation

Bug: T234016
Change-Id: I3dc96d394d8b98dda8f151d14544b829c92f9b10

tests/phpunit/includes/api/ApiQuerySiteinfoTest.php

index dce1a5f..7f5ee0c 100644 (file)
@@ -665,17 +665,13 @@ class ApiQuerySiteinfoTest extends ApiTestCase {
        }
 
        public function testContinuation() {
-               // We make lots and lots of URL protocols that are each 100 bytes
+               // Use $wgUrlProtocols to forge the size of the API query
                global $wgAPIMaxResultSize, $wgUrlProtocols;
 
-               $this->setMwGlobals( 'wgUrlProtocols', [] );
+               $protocol = 'foo://';
 
-               // Just under the limit
-               $chunks = $wgAPIMaxResultSize / 100 - 1;
-
-               for ( $i = 0; $i < $chunks; $i++ ) {
-                       $wgUrlProtocols[] = substr( str_repeat( "$i ", 50 ), 0, 100 );
-               }
+               $this->setMwGlobals( 'wgUrlProtocols', [ $protocol ] );
+               $this->setMwGlobals( 'wgAPIMaxResultSize', strlen( $protocol ) );
 
                $res = $this->doApiRequest( [
                        'action' => 'query',