We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
passenger / test / SpawnManagerTest.cpp
b9e7f403 » Hongli Lai (Phusion) 2008-01-31 Add a C++ SpawnManager clas... 1 #include "tut.h"
2 #include "SpawnManager.h"
54c79b53 » Hongli Lai (Phusion) 2008-02-18 - Change the way spawn serv... 3 #include <sys/types.h>
4 #include <signal.h>
b9e7f403 » Hongli Lai (Phusion) 2008-01-31 Add a C++ SpawnManager clas... 5 #include <cstring>
6 #include <unistd.h>
4551a604 » Hongli Lai (Phusion) 2008-02-22 SpawnManager: catch a previ... 7 #include "valgrind.h"
b9e7f403 » Hongli Lai (Phusion) 2008-01-31 Add a C++ SpawnManager clas... 8
9 using namespace Passenger;
10
11 namespace tut {
12 struct SpawnManagerTest {
d90c4d0a » Hongli Lai (Phusion) 2008-02-18 - Improve documentation. 13 SpawnManager manager;
14
15 SpawnManagerTest(): manager("stub/spawn_server.rb") {}
b9e7f403 » Hongli Lai (Phusion) 2008-01-31 Add a C++ SpawnManager clas... 16 };
17
18 DEFINE_TEST_GROUP(SpawnManagerTest);
19
20 TEST_METHOD(1) {
21 // Spawning an application should return a valid Application object.
22 ApplicationPtr app(manager.spawn("."));
f9548739 » Hongli Lai (Phusion) 2008-02-06 - Refactor ApplicationPool ... 23 ensure_equals("The Application object's PID is the same as the one specified by the stub",
b9e7f403 » Hongli Lai (Phusion) 2008-01-31 Add a C++ SpawnManager clas... 24 app->getPid(), 1234);
25 }
a1669337 » Hongli Lai (Phusion) 2008-02-07 Add TODO items 26
27 TEST_METHOD(2) {
d90c4d0a » Hongli Lai (Phusion) 2008-02-18 - Improve documentation. 28 // If something goes wrong during spawning, the spawn manager
54c79b53 » Hongli Lai (Phusion) 2008-02-18 - Change the way spawn serv... 29 // should be restarted and another (successful) spawn should be attempted.
4551a604 » Hongli Lai (Phusion) 2008-02-22 SpawnManager: catch a previ... 30 pid_t old_pid = manager.getServerPid();
31 kill(manager.getServerPid(), SIGTERM);
32 // Give the spawn server the time to properly terminate.
33 usleep(500000);
34
d90c4d0a » Hongli Lai (Phusion) 2008-02-18 - Improve documentation. 35 ApplicationPtr app(manager.spawn("."));
36 ensure_equals("The Application object's PID is the same as the one specified by the stub",
37 app->getPid(), 1234);
4551a604 » Hongli Lai (Phusion) 2008-02-22 SpawnManager: catch a previ... 38
39 // The following test will fail if we're inside Valgrind, but that's normal.
911462eb » Hongli Lai (Phusion) 2008-02-23 The request handler now lis... 40 // Killing the spawn server doesn't work.
4551a604 » Hongli Lai (Phusion) 2008-02-22 SpawnManager: catch a previ... 41 if (!RUNNING_ON_VALGRIND) {
42 ensure("The spawn server was restarted", manager.getServerPid() != old_pid);
43 }
44 }
45
46 TEST_METHOD(3) {
911462eb » Hongli Lai (Phusion) 2008-02-23 The request handler now lis... 47 // This test fails in Valgrind, but that's normal.
48 // Killing the spawn server doesn't work.
49 if (!RUNNING_ON_VALGRIND) {
50 // If the spawn server dies after a restart, a SpawnException should be thrown.
51 kill(manager.getServerPid(), SIGTERM);
52 // Give the spawn server the time to properly terminate.
53 usleep(500000);
4551a604 » Hongli Lai (Phusion) 2008-02-22 SpawnManager: catch a previ... 54
911462eb » Hongli Lai (Phusion) 2008-02-23 The request handler now lis... 55 try {
56 manager.nextRestartShouldFail = true;
57 ApplicationPtr app(manager.spawn("."));
58 fail("SpawnManager did not throw a SpawnException");
59 } catch (const SpawnException &e) {
60 // Success.
61 }
4551a604 » Hongli Lai (Phusion) 2008-02-22 SpawnManager: catch a previ... 62 }
a1669337 » Hongli Lai (Phusion) 2008-02-07 Add TODO items 63 }
b9e7f403 » Hongli Lai (Phusion) 2008-01-31 Add a C++ SpawnManager clas... 64 }