https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115453
Revision: 115453 Author: maxsem Date: 2012-05-28 23:02:18 +0000 (Mon, 28 May 2012) Log Message: ----------- Basic tests for redirector.c Added Paths: ----------- trunk/debs/squid/test-redirector.php Added: trunk/debs/squid/test-redirector.php =================================================================== --- trunk/debs/squid/test-redirector.php (rev 0) +++ trunk/debs/squid/test-redirector.php 2012-05-28 23:02:18 UTC (rev 115453) @@ -0,0 +1,70 @@ +<?php + +$descriptorspec = array( + 0 => array( 'pipe', 'r' ), + 1 => array( 'pipe', 'w' ), + 2 => array( 'pipe', 'w' ), +); + +$pipes = array(); +$proc = proc_open( './redirector', $descriptorspec, $pipes ); +list( $stdin, $stdout, $stderr ) = $pipes; + +function closeall() { + global $stdin, $stdout, $stderr; + fclose( $stdin ); + fclose( $stdout ); + fclose( $stderr ); +} + +function dieout( $err ) { + global $proc; + proc_close( $proc ); + closeall(); + fwrite( STDERR, "{$err}\n" ); + die( 1 ); +} + +function io( $url ) { + global $stdin, $stdout, $stderr; + $channel = mt_rand( 100, 999 ); // keep the length consistent + fwrite( $stdin, "{$channel} {$url} some other params\n" ); + /*if ( !feof( $stderr ) ) { + $err = fgets( $stderr ); + dieout( "STDERR output: {$err}" ); + }*/ + $line = trim( fgets( $stdout ) ); + $parts = explode( ' ', $line ); + if ( count( $parts ) != 2 ) { + dieout( "{$url} : invalid response '{$line}'" ); + } + list( $outChan, $result ) = $parts; + if ( $outChan != $channel ) { + dieout( "Expected channel {$channel}, got {$outChan}" ); + } + return $result; +} + +$longUrl = 'http://en.wikipedia.org/I_am_a_ridiculous_URL_' . str_repeat( 'X', 5000 ); +$anotherLongUrl = 'http://en.wikipedia.org/wiki/I_am_a_ridiculous_URL_' . str_repeat( 'X', 5000 ); +$overflow = 'http://sq.wiktionary.org/w/index.php?foo=' . str_repeat( 'X', 100500 ); + +$testCases = array( + 'http://en.wikipedia.org' => 'http://en.wikipedia.org', + 'http://en.wikipedia.org/w/' => 'http://en.wikipedia.org/w/', + 'http://en.wikipedia.org/w/index.php?foo=bar' => 'http://en.wikipedia.org/w/index.php?foo=bar', + $anotherLongUrl => "302:http://en.m.wikipedia.org/wiki/I_am_a_ridiculous_URL_" . str_repeat( 'X', 5000 ), + $overflow => substr( $overflow, 0, 8251 ), +); + +foreach( $testCases as $input => $expected ) { + $result = io( $input ); + if ( $result != $expected ) { + dieout( "Input {$input}: expected {$expected}, got {$result}" ); + } +} + +closeall(); +proc_close( $proc ); + +echo "No errors found!\n"; Property changes on: trunk/debs/squid/test-redirector.php ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs