2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/test/test_ext_server.h"
18 #include "hphp/runtime/ext/ext_server.h"
19 #include "hphp/runtime/base/server/pagelet_server.h"
20 #include "hphp/runtime/base/server/xbox_server.h"
21 #include "hphp/runtime/base/runtime_option.h"
22 #include "hphp/runtime/ext/ext_file.h"
24 ///////////////////////////////////////////////////////////////////////////////
26 bool TestExtServer::RunTests(const std::string
&which
) {
29 DECLARE_TEST_FUNCTIONS("");
31 std::string root
= std::string(f_getcwd().toString().c_str()) + "/test/";
33 RuntimeOption::SourceRoot
= root
;
34 RuntimeOption::PageletServerThreadCount
= 10;
35 PageletServer::Restart();
37 RuntimeOption::XboxServerThreadCount
= 10;
38 RuntimeOption::XboxServerInfoReqInitDoc
= root
+ "test_xbox_init.php";
39 XboxServer::Restart();
41 RUN_TEST(test_dangling_server_proxy_old_request
);
42 RUN_TEST(test_dangling_server_proxy_new_request
);
43 RUN_TEST(test_pagelet_server_task_start
);
44 RUN_TEST(test_pagelet_server_task_status
);
45 RUN_TEST(test_pagelet_server_task_result
);
46 RUN_TEST(test_xbox_send_message
);
47 RUN_TEST(test_xbox_post_message
);
48 RUN_TEST(test_xbox_task_start
);
49 RUN_TEST(test_xbox_task_status
);
50 RUN_TEST(test_xbox_task_result
);
55 ///////////////////////////////////////////////////////////////////////////////
57 bool TestExtServer::test_dangling_server_proxy_old_request() {
61 bool TestExtServer::test_dangling_server_proxy_new_request() {
65 ///////////////////////////////////////////////////////////////////////////////
66 // Pagelet Server unit test
68 bool TestExtServer::test_pagelet_server_task_start() {
69 // tested in test_pagelet_server_task_result()
73 bool TestExtServer::test_pagelet_server_task_status() {
74 // tested in test_pagelet_server_task_result()
78 bool TestExtServer::test_pagelet_server_task_result() {
79 const int TEST_SIZE
= 20;
81 String
baseurl("pageletserver?getparam=");
82 String
baseheader("MyHeader: ");
83 String
basepost("postparam=");
85 std::vector
<Object
> tasks
;
86 for (int i
= 0; i
< TEST_SIZE
; ++i
) {
87 String url
= baseurl
+ String(i
);
88 String header
= baseheader
+ String(i
);
89 String post
= basepost
+ String(i
);
90 Object task
= f_pagelet_server_task_start(url
, CREATE_VECTOR1(header
),
92 tasks
.push_back(task
);
95 for (int i
= 0; i
< TEST_SIZE
; ++i
) {
96 f_pagelet_server_task_status(tasks
[i
]);
99 // Calls that time out (try 1 ms) should return a status code of -1
100 for (int i
= 0; i
< TEST_SIZE
; ++i
) {
101 Variant code
, headers
;
102 VS("", f_pagelet_server_task_result(tasks
[i
], ref(headers
), ref(code
), 1));
106 for (int i
= 0; i
< TEST_SIZE
; ++i
) {
107 String expected
= "pagelet postparam: postparam=";
108 expected
+= String(i
);
109 expected
+= "pagelet getparam: ";
110 expected
+= String(i
);
111 expected
+= "pagelet header: ";
112 expected
+= String(i
);
114 // A timeout of 0 indicates an infinite timeout that blocks.
115 Variant code
, headers
;
116 VS(expected
, f_pagelet_server_task_result(tasks
[i
], ref(headers
),
119 VS(headers
[1], "ResponseHeader: okay");
121 VS(expected
, f_pagelet_server_task_result(tasks
[i
], ref(headers
),
129 ///////////////////////////////////////////////////////////////////////////////
131 bool TestExtServer::test_xbox_send_message() {
132 static const StaticString
134 s_response("response");
136 VERIFY(f_xbox_send_message("hello", ref(ret
), 5000));
137 VS(ret
[s_code
], 200);
138 VS(ret
[s_response
], "olleh");
142 bool TestExtServer::test_xbox_post_message() {
143 VERIFY(f_xbox_post_message("hello"));
147 bool TestExtServer::test_xbox_task_start() {
148 // tested in test_xbox_task_result()
152 bool TestExtServer::test_xbox_task_status() {
153 // tested in test_xbox_task_result()
157 bool TestExtServer::test_xbox_task_result() {
158 Object task
= f_xbox_task_start("hello");
159 f_xbox_task_status(task
);
161 VS(f_xbox_task_result(task
, 0, ref(ret
)), 200);