test/cxx/ApplicationPool2/SmartSpawnerTest.cpp in passenger-3.9.1.beta vs test/cxx/ApplicationPool2/SmartSpawnerTest.cpp in passenger-3.9.2.beta
- old
+ new
@@ -3,10 +3,11 @@
#include <Logging.h>
#include <Utils/json.h>
#include <unistd.h>
#include <climits>
#include <signal.h>
+#include <fcntl.h>
using namespace std;
using namespace Passenger;
using namespace Passenger::ApplicationPool2;
@@ -60,11 +61,11 @@
// If the preloader has crashed then SmartSpawner will
// restart it and try again.
Options options = createOptions();
options.appRoot = "stub/rack";
options.startCommand = "ruby\1" "start.rb";
- options.startupFile = "stub/rack/start.rb";
+ options.startupFile = "start.rb";
shared_ptr<SmartSpawner> spawner = createSpawner(options);
spawner->spawn(options);
kill(spawner->getPreloaderPid(), SIGTERM);
// Give it some time to exit.
@@ -79,11 +80,11 @@
// If the preloader still crashes after the restart then
// SmartSpawner will throw an exception.
Options options = createOptions();
options.appRoot = "stub/rack";
options.startCommand = "ruby\1" "start.rb";
- options.startupFile = "stub/rack/start.rb";
+ options.startupFile = "start.rb";
setLogLevel(-1);
shared_ptr<SmartSpawner> spawner = createSpawner(options, true);
try {
spawner->spawn(options);
fail("SpawnException expected");
@@ -97,11 +98,11 @@
// then it's killed and an exception is thrown, with
// whatever stderr output as error page.
Options options = createOptions();
options.appRoot = "stub/rack";
options.startCommand = "ruby\1" "start.rb";
- options.startupFile = "stub/rack/start.rb";
+ options.startupFile = "start.rb";
options.startTimeout = 300;
vector<string> preloaderCommand;
preloaderCommand.push_back("bash");
preloaderCommand.push_back("-c");
@@ -109,12 +110,12 @@
SmartSpawner spawner(bg.safe,
*resourceLocator,
generation,
preloaderCommand,
options);
- spawner.forwardStdout = false;
- spawner.forwardStderr = false;
+ spawner.getConfig()->forwardStdout = false;
+ spawner.getConfig()->forwardStderr = false;
try {
spawner.spawn(options);
fail("SpawnException expected");
} catch (const SpawnException &e) {
@@ -130,23 +131,23 @@
// a proper error response, then its stderr output is used
// as error response instead.
Options options = createOptions();
options.appRoot = "stub/rack";
options.startCommand = "ruby\1" "start.rb";
- options.startupFile = "stub/rack/start.rb";
+ options.startupFile = "start.rb";
vector<string> preloaderCommand;
preloaderCommand.push_back("bash");
preloaderCommand.push_back("-c");
preloaderCommand.push_back("echo hello world >&2");
SmartSpawner spawner(bg.safe,
*resourceLocator,
generation,
preloaderCommand,
options);
- spawner.forwardStdout = false;
- spawner.forwardStderr = false;
+ spawner.getConfig()->forwardStdout = false;
+ spawner.getConfig()->forwardStderr = false;
try {
spawner.spawn(options);
fail("SpawnException expected");
} catch (const SpawnException &e) {
@@ -161,11 +162,11 @@
// If the preloader encountered an error, then the resulting SpawnException
// takes note of the process's environment variables.
Options options = createOptions();
options.appRoot = "stub/rack";
options.startCommand = "ruby\1" "start.rb";
- options.startupFile = "stub/rack/start.rb";
+ options.startupFile = "start.rb";
options.environmentVariables.push_back(make_pair("PASSENGER_FOO", "foo"));
vector<string> preloaderCommand;
preloaderCommand.push_back("bash");
preloaderCommand.push_back("-c");
@@ -173,12 +174,12 @@
SmartSpawner spawner(bg.safe,
*resourceLocator,
generation,
preloaderCommand,
options);
- spawner.forwardStdout = false;
- spawner.forwardStderr = false;
+ spawner.getConfig()->forwardStdout = false;
+ spawner.getConfig()->forwardStderr = false;
try {
spawner.spawn(options);
fail("SpawnException expected");
} catch (const SpawnException &e) {
@@ -188,10 +189,11 @@
TEST_METHOD(85) {
// Test that the spawned process can still write to its stderr
// after the SmartSpawner has been destroyed.
DeleteFileEventually d("tmp.output");
+ FileDescriptor output(open("tmp.output", O_WRONLY | O_CREAT | O_TRUNC, 0600));
Options options = createOptions();
options.appRoot = "stub/rack";
ProcessPtr process;
{
@@ -201,10 +203,12 @@
SmartSpawner spawner(bg.safe,
*resourceLocator,
generation,
preloaderCommand,
options);
+ spawner.getConfig()->forwardStdoutTo = output;
+ spawner.getConfig()->forwardStderrTo = output;
process = spawner.spawn(options);
}
SessionPtr session = process->newSession();
session->initiate();
@@ -216,14 +220,13 @@
data.append("PASSENGER_CONNECT_PASSWORD");
data.append(1, '\0');
data.append(process->connectPassword);
data.append(1, '\0');
- {
- TemporarilyRedirectStdio redirect("tmp.output");
- writeScalarMessage(session->fd(), data);
- shutdown(session->fd(), SHUT_WR);
- readAll(session->fd());
- }
- ensure_equals(readAll("tmp.output"), "hello world!\n");
+ writeScalarMessage(session->fd(), data);
+ shutdown(session->fd(), SHUT_WR);
+ readAll(session->fd());
+ EVENTUALLY(2,
+ result = readAll("tmp.output").find("hello world!\n") != string::npos;
+ );
}
}