Sha256: bad78dbf42198b0e5381725df8e250d3fe3e2993a0e73d4429d58c4c5c39de73

Contents?: true

Size: 1.9 KB

Versions: 24

Compression:

Stored size: 1.9 KB

Contents

#include "tut.h"
#include "SpawnManager.h"
#include <sys/types.h>
#include <signal.h>
#include <cstring>
#include <unistd.h>
#include "valgrind.h"

using namespace Passenger;

namespace tut {
	struct SpawnManagerTest {
		SpawnManager manager;
		
		SpawnManagerTest(): manager("stub/spawn_server.rb") {}
	};

	DEFINE_TEST_GROUP(SpawnManagerTest);

	TEST_METHOD(1) {
		// Spawning an application should return a valid Application object.
		ApplicationPtr app(manager.spawn(PoolOptions(".")));
		ensure_equals("The Application object's PID is the same as the one specified by the stub",
			app->getPid(), 1234);
	}
	
	TEST_METHOD(2) {
		// If something goes wrong during spawning, the spawn manager
		// should be restarted and another (successful) spawn should be attempted.
		pid_t old_pid = manager.getServerPid();
		kill(manager.getServerPid(), SIGTERM);
		// Give the spawn server the time to properly terminate.
		usleep(500000);
		
		ApplicationPtr app(manager.spawn(PoolOptions(".")));
		ensure_equals("The Application object's PID is the same as the one specified by the stub",
			app->getPid(), 1234);
		
		// The following test will fail if we're inside Valgrind, but that's normal.
		// Killing the spawn server doesn't work.
		if (!RUNNING_ON_VALGRIND) {
			ensure("The spawn server was restarted", manager.getServerPid() != old_pid);
		}
	}
	
	TEST_METHOD(3) {
		// This test fails in Valgrind, but that's normal.
		// Killing the spawn server doesn't work.
		if (!RUNNING_ON_VALGRIND) {
			// If the spawn server dies after a restart, a SpawnException should be thrown.
			kill(manager.getServerPid(), SIGTERM);
			// Give the spawn server the time to properly terminate.
			usleep(500000);
			
			try {
				manager.nextRestartShouldFail = true;
				ApplicationPtr app(manager.spawn(PoolOptions(".")));
				fail("SpawnManager did not throw a SpawnException");
			} catch (const SpawnException &e) {
				// Success.
			}
		}
	}
}

Version data entries

24 entries across 24 versions & 5 rubygems

Version Path
rockdog-passenger-0.0.1 test/SpawnManagerTest.cpp
vanity-1.7.1 vendor/ruby/1.9.1/gems/passenger-2.2.15/test/SpawnManagerTest.cpp
passenger-2.2.15 test/SpawnManagerTest.cpp
passenger-2.2.14 test/SpawnManagerTest.cpp
passenger-2.2.13 test/SpawnManagerTest.cpp
passenger-2.2.12 test/SpawnManagerTest.cpp
colouringcode-passenger-0.2 test/SpawnManagerTest.cpp
passenger-2.2.11 test/SpawnManagerTest.cpp
passenger-jmazzi-2.2.10 test/SpawnManagerTest.cpp
passenger-2.2.10 test/SpawnManagerTest.cpp
passenger-jmazzi-2.2.9 test/SpawnManagerTest.cpp
passenger-2.2.9 test/SpawnManagerTest.cpp
passenger-2.2.8 test/SpawnManagerTest.cpp
colouringcode-passenger-0.1 test/SpawnManagerTest.cpp
passenger-2.2.7 test/SpawnManagerTest.cpp
passenger-2.2.6 test/SpawnManagerTest.cpp
passenger-2.2.5 test/SpawnManagerTest.cpp
passenger-2.2.3 test/SpawnManagerTest.cpp
passenger-2.2.4 test/SpawnManagerTest.cpp
passenger-2.1.2 test/SpawnManagerTest.cpp