Skip to content
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"require-dev": {
"guzzle/plugin-mock": "*",
"mockery/mockery": "*",
"monolog/monolog": "*"
"monolog/monolog": "*",
"symfony/process": "~2.3"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require LTS version.

},
"suggest": {
"monolog/monolog": "For logging issues while invalidating"
Expand Down
16 changes: 12 additions & 4 deletions tests/VarnishTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FOS\HttpCache\Tests;

use FOS\HttpCache\ProxyClient\Varnish;
use Symfony\Component\Process\Process;

/**
* A phpunit base class to write functional tests with varnish.
Expand Down Expand Up @@ -143,7 +144,8 @@ protected function tearDown()
protected function stopVarnish()
{
if (file_exists(self::PID)) {
exec('kill -9 ' . file_get_contents(self::PID));
$process = new Process('kill -9 ' . file_get_contents(self::PID));
$process->run(); // Ignore if command fails when Varnish wasn't running
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also doing this through process to suppress warning sh: 1: kill: No such process. After all, it doesn’t really matter if we try to kill Varnish when it wasn’t running.

I also tried to make $process a static class var that we could then call stop() on, but that didn’t shut down Varnish. Probably has something to do with the varnishd command spawning/forking a different process and storing that PID in the PID file. Stopping the original varnishd command still keeps Varnish running, which is not what we want.

unlink(self::PID);
$this->waitUntil('127.0.0.1', $this->getCachingProxyPort(), 2000);
}
Expand All @@ -154,14 +156,20 @@ protected function stopVarnish()
*/
protected function startVarnish()
{
exec($this->getBinary() .
$cmd = $this->getBinary() .
' -a 127.0.0.1:' . $this->getCachingProxyPort() .
' -T 127.0.0.1:' . $this->getVarnishMgmtPort() .
' -f ' . $this->getConfigFile() .
' -n ' . $this->getCacheDir() .
' -p vcl_dir=' . $this->getConfigDir() .
' -P ' . self::PID
);
' -P ' . self::PID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest building this through the PRocessBuilder rather than using string concatenation, as this is missing shell escaping (if you have a space in the path to your config file, it will explode in your face for instance)


$process = new Process($cmd);
$process->run();

if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}

$this->waitFor('127.0.0.1', $this->getCachingProxyPort(), 2000);
}
Expand Down