Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Process] Fix transient tests for incremental outputs #17650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if ('phpdbg' === PHP_SAPI) {
$PHP .= ' -qrr';
}

$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? `where.exe composer.phar` : `which composer.phar`))
$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
? $PHP.' '.ProcessUtils::escapeArgument($COMPOSER)
: 'composer';

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ public function testVeryLongHosts($host)
$request = Request::create('/');
$request->headers->set('host', $host);
$this->assertEquals($host, $request->getHost());
$this->assertLessThan(1, microtime(true) - $start);
$this->assertLessThan(3, microtime(true) - $start);
}

/**
Expand Down
116 changes: 24 additions & 92 deletions 116 src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,56 +290,40 @@ public function testGetErrorOutput()
$this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches));
}

public function testGetIncrementalErrorOutput()
/**
* @dataProvider provideIncrementalOutput
*/
public function testIncrementalOutput($getOutput, $getIncrementalOutput, $uri)
{
// use a lock file to toggle between writing ("W") and reading ("R") the
// error stream
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
file_put_contents($lock, 'W');
$lock = tempnam(sys_get_temp_dir(), __FUNCTION__);

$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));
$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('file_put_contents($s = \''.$uri.'\', \'foo\'); flock(fopen('.var_export($lock, true).', \'r\'), LOCK_EX); file_put_contents($s, \'bar\');')));

$p->start();
while ($p->isRunning()) {
if ('R' === file_get_contents($lock)) {
$this->assertLessThanOrEqual(1, preg_match_all('/ERROR/', $p->getIncrementalErrorOutput(), $matches));
file_put_contents($lock, 'W');
}
usleep(100);
}

unlink($lock);
}

public function testGetEmptyIncrementalErrorOutput()
{
// use a lock file to toggle between writing ("W") and reading ("R") the
// output stream
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
file_put_contents($lock, 'W');

$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));
$h = fopen($lock, 'w');
flock($h, LOCK_EX);

$p->start();

$shouldWrite = false;
foreach (array('foo', 'bar') as $s) {
while (false === strpos($p->$getOutput(), $s)) {
usleep(1000);
}

while ($p->isRunning()) {
if ('R' === file_get_contents($lock)) {
if (!$shouldWrite) {
$this->assertLessThanOrEqual(1, preg_match_all('/ERROR/', $p->getIncrementalOutput(), $matches));
$shouldWrite = true;
} else {
$this->assertSame('', $p->getIncrementalOutput());
$this->assertSame($s, $p->$getIncrementalOutput());
$this->assertSame('', $p->$getIncrementalOutput());

file_put_contents($lock, 'W');
$shouldWrite = false;
}
}
usleep(100);
flock($h, LOCK_UN);
}

unlink($lock);
fclose($h);
}

public function provideIncrementalOutput()
{
return array(
array('getOutput', 'getIncrementalOutput', 'php://stdout'),
array('getErrorOutput', 'getIncrementalErrorOutput', 'php://stderr'),
);
}

public function testGetOutput()
Expand All @@ -350,58 +334,6 @@ public function testGetOutput()
$this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches));
}

public function testGetIncrementalOutput()
{
// use a lock file to toggle between writing ("W") and reading ("R") the
// output stream
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
file_put_contents($lock, 'W');

$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));

$p->start();
while ($p->isRunning()) {
if ('R' === file_get_contents($lock)) {
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
file_put_contents($lock, 'W');
}
usleep(100);
}

unlink($lock);
}

public function testGetEmptyIncrementalOutput()
{
// use a lock file to toggle between writing ("W") and reading ("R") the
// output stream
$lock = tempnam(sys_get_temp_dir(), get_class($this).'Lock');
file_put_contents($lock, 'W');

$p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents('.var_export($lock, true).')) { echo \' foo \'; $n++; file_put_contents('.var_export($lock, true).', \'R\'); } usleep(100); }')));

$p->start();

$shouldWrite = false;

while ($p->isRunning()) {
if ('R' === file_get_contents($lock)) {
if (!$shouldWrite) {
$this->assertLessThanOrEqual(1, preg_match_all('/foo/', $p->getIncrementalOutput(), $matches));
$shouldWrite = true;
} else {
$this->assertSame('', $p->getIncrementalOutput());

file_put_contents($lock, 'W');
$shouldWrite = false;
}
}
usleep(100);
}

unlink($lock);
}

public function testZeroAsOutput()
{
if ('\\' === DIRECTORY_SEPARATOR) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.