File: ApplicationPool_Server_PoolTest.cpp

package info (click to toggle)
ruby-passenger 3.0.13debian-1%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,920 kB
  • sloc: cpp: 99,104; ruby: 18,098; ansic: 9,846; sh: 8,632; python: 141; makefile: 30
file content (80 lines) | stat: -rw-r--r-- 2,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "TestSupport.h"

#include <string>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>

#include "ApplicationPool/Pool.h"
#include "ApplicationPool/Server.h"
#include "ApplicationPool/Client.h"
#include "Utils.h"

using namespace Passenger;
using namespace std;
using namespace boost;

namespace tut {
	struct ApplicationPool_Server_PoolTest {
		ServerInstanceDirPtr serverInstanceDir;
		ServerInstanceDir::GenerationPtr generation;
		AccountsDatabasePtr accountsDatabase;
		shared_ptr<MessageServer> messageServer;
		shared_ptr<ApplicationPool::Pool> realPool;
		shared_ptr<ApplicationPool::Server> poolServer;
		shared_ptr<ApplicationPool::Client> pool, pool2;
		shared_ptr<oxt::thread> serverThread;
		string socketFilename;
		
		ApplicationPool_Server_PoolTest() {
			createServerInstanceDirAndGeneration(serverInstanceDir, generation);
			socketFilename = generation->getPath() + "/socket";
			accountsDatabase = ptr(new AccountsDatabase());
			accountsDatabase->add("test", "12345", false);
			
			messageServer = ptr(new MessageServer(socketFilename, accountsDatabase));
			realPool      = ptr(new ApplicationPool::Pool("../helper-scripts/passenger-spawn-server", generation));
			poolServer    = ptr(new ApplicationPool::Server(realPool));
			messageServer->addHandler(poolServer);
			serverThread = ptr(new oxt::thread(
				boost::bind(&MessageServer::mainLoop, messageServer.get())
			));
			pool  = newPoolConnection();
			pool2 = newPoolConnection();
		}
		
		~ApplicationPool_Server_PoolTest() {
			if (serverThread != NULL) {
				serverThread->interrupt_and_join();
			}
		}
		
		void reinitializeWithSpawnManager(AbstractSpawnManagerPtr spawnManager) {
			if (serverThread != NULL) {
				serverThread->interrupt_and_join();
			}
			
			messageServer.reset(); // Wait until the previous instance has removed the socket.
			messageServer = ptr(new MessageServer(socketFilename, accountsDatabase));
			realPool      = ptr(new ApplicationPool::Pool(spawnManager));
			poolServer    = ptr(new ApplicationPool::Server(realPool));
			messageServer->addHandler(poolServer);
			serverThread = ptr(new oxt::thread(
				boost::bind(&MessageServer::mainLoop, messageServer.get())
			));
			pool  = newPoolConnection();
			pool2 = newPoolConnection();
		}
		
		shared_ptr<ApplicationPool::Client> newPoolConnection() {
			shared_ptr<ApplicationPool::Client> p(new ApplicationPool::Client());
			p->connect(socketFilename, "test", "12345");
			return p;
		}
	};
	
	DEFINE_TEST_GROUP(ApplicationPool_Server_PoolTest);
	
	#define USE_TEMPLATE
	#include "ApplicationPool_PoolTestCases.cpp"
}