This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Hongli Lai (Phusion) (author)
Thu May 01 08:44:22 -0700 2008
| b9e7f403 » | Hongli Lai (Phusion) | 2008-01-31 | 1 | #include "tut.h" | |
| 2 | #include "SpawnManager.h" | ||||
| 54c79b53 » | Hongli Lai (Phusion) | 2008-02-18 | 3 | #include <sys/types.h> | |
| 4 | #include <signal.h> | ||||
| b9e7f403 » | Hongli Lai (Phusion) | 2008-01-31 | 5 | #include <cstring> | |
| 6 | #include <unistd.h> | ||||
| 4551a604 » | Hongli Lai (Phusion) | 2008-02-22 | 7 | #include "valgrind.h" | |
| b9e7f403 » | Hongli Lai (Phusion) | 2008-01-31 | 8 | ||
| 9 | using namespace Passenger; | ||||
| 10 | |||||
| 11 | namespace tut { | ||||
| 12 | struct SpawnManagerTest { | ||||
| d90c4d0a » | Hongli Lai (Phusion) | 2008-02-18 | 13 | SpawnManager manager; | |
| 14 | |||||
| 15 | SpawnManagerTest(): manager("stub/spawn_server.rb") {} | ||||
| b9e7f403 » | Hongli Lai (Phusion) | 2008-01-31 | 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 | 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 | 24 | app->getPid(), 1234); | |
| 25 | } | ||||
| a1669337 » | Hongli Lai (Phusion) | 2008-02-07 | 26 | ||
| 27 | TEST_METHOD(2) { | ||||
| d90c4d0a » | Hongli Lai (Phusion) | 2008-02-18 | 28 | // If something goes wrong during spawning, the spawn manager | |
| 54c79b53 » | Hongli Lai (Phusion) | 2008-02-18 | 29 | // should be restarted and another (successful) spawn should be attempted. | |
| 4551a604 » | Hongli Lai (Phusion) | 2008-02-22 | 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 | 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 | 38 | ||
| 39 | // The following test will fail if we're inside Valgrind, but that's normal. | ||||
| 911462eb » | Hongli Lai (Phusion) | 2008-02-23 | 40 | // Killing the spawn server doesn't work. | |
| 4551a604 » | Hongli Lai (Phusion) | 2008-02-22 | 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 | 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 | 54 | ||
| 911462eb » | Hongli Lai (Phusion) | 2008-02-23 | 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 | 62 | } | |
| a1669337 » | Hongli Lai (Phusion) | 2008-02-07 | 63 | } | |
| b9e7f403 » | Hongli Lai (Phusion) | 2008-01-31 | 64 | } | |






