84b9d9a3a2
In HHVM (and HPHPc before it) we've been piggybacking resources on the KindOfObject machinery. At the language level, resource is considered to be a different type than object, and there are a number of differences in behavior between objects and resources (ex. resources don't allow for dynamic properties, resources don't work with the clone operator, the "(object)" cast behaves differently for resources vs. objects, etc). Piggybacking resources on the KindOfObject machinery has some downsides. Code that deals with KindOfObject values often needs to check if the value is a resource and go down a different code path. This makes things harder to maintain and harder to keep parity with Zend. Also, these extra branches hurt performance a little, and they make it harder for the JIT to do a good job in some cases when its generating machine code that operates on objects. This diff prepares the code base for a new KindOfResource type by adding a new "Resource" smart pointer type (currently a typedef for the Object smart pointer type) and it updates the C++ code and the idl files appropriately. This diff is essentially a cosmetic change and should not impact run time behavior. In the next diff (part 2) we'll actually add a new KindOfResource type, detach ResourceData from the ObjectData inheritence hierarchy, and provide a real implementation for the Resource smart pointer type (instead of just aliasing the Object smart pointer type).
165 linhas
5.3 KiB
C++
165 linhas
5.3 KiB
C++
/*
|
|
+----------------------------------------------------------------------+
|
|
| HipHop for PHP |
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| http://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#include "hphp/test/ext/test_ext_server.h"
|
|
#include "hphp/runtime/ext/ext_server.h"
|
|
#include "hphp/runtime/base/server/pagelet_server.h"
|
|
#include "hphp/runtime/base/server/xbox_server.h"
|
|
#include "hphp/runtime/base/runtime_option.h"
|
|
#include "hphp/runtime/ext/ext_file.h"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool TestExtServer::RunTests(const std::string &which) {
|
|
bool ret = true;
|
|
|
|
DECLARE_TEST_FUNCTIONS("");
|
|
|
|
std::string root = std::string(f_getcwd().toString().c_str()) + "/test/ext/";
|
|
|
|
RuntimeOption::SourceRoot = root;
|
|
RuntimeOption::PageletServerThreadCount = 10;
|
|
PageletServer::Restart();
|
|
|
|
RuntimeOption::XboxServerThreadCount = 10;
|
|
RuntimeOption::XboxServerInfoReqInitDoc = root + "test_xbox_init.php";
|
|
XboxServer::Restart();
|
|
|
|
RUN_TEST(test_dangling_server_proxy_old_request);
|
|
RUN_TEST(test_dangling_server_proxy_new_request);
|
|
RUN_TEST(test_pagelet_server_task_start);
|
|
RUN_TEST(test_pagelet_server_task_status);
|
|
RUN_TEST(test_pagelet_server_task_result);
|
|
RUN_TEST(test_xbox_send_message);
|
|
RUN_TEST(test_xbox_post_message);
|
|
RUN_TEST(test_xbox_task_start);
|
|
RUN_TEST(test_xbox_task_status);
|
|
RUN_TEST(test_xbox_task_result);
|
|
|
|
return ret;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool TestExtServer::test_dangling_server_proxy_old_request() {
|
|
return Count(true);
|
|
}
|
|
|
|
bool TestExtServer::test_dangling_server_proxy_new_request() {
|
|
return Count(true);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Pagelet Server unit test
|
|
|
|
bool TestExtServer::test_pagelet_server_task_start() {
|
|
// tested in test_pagelet_server_task_result()
|
|
return Count(true);
|
|
}
|
|
|
|
bool TestExtServer::test_pagelet_server_task_status() {
|
|
// tested in test_pagelet_server_task_result()
|
|
return Count(true);
|
|
}
|
|
|
|
bool TestExtServer::test_pagelet_server_task_result() {
|
|
const int TEST_SIZE = 20;
|
|
|
|
String baseurl("ext/pageletserver?getparam=");
|
|
String baseheader("MyHeader: ");
|
|
String basepost("postparam=");
|
|
|
|
std::vector<Resource> tasks;
|
|
for (int i = 0; i < TEST_SIZE; ++i) {
|
|
String url = baseurl + String(i);
|
|
String header = baseheader + String(i);
|
|
String post = basepost + String(i);
|
|
Resource task = f_pagelet_server_task_start(url, CREATE_VECTOR1(header),
|
|
post);
|
|
tasks.push_back(task);
|
|
}
|
|
|
|
for (int i = 0; i < TEST_SIZE; ++i) {
|
|
f_pagelet_server_task_status(tasks[i]);
|
|
}
|
|
|
|
// Calls that time out (try 1 ms) should return a status code of -1
|
|
for (int i = 0; i < TEST_SIZE; ++i) {
|
|
Variant code, headers;
|
|
VS("", f_pagelet_server_task_result(tasks[i], ref(headers), ref(code), 1));
|
|
VS(code, -1);
|
|
}
|
|
|
|
for (int i = 0; i < TEST_SIZE; ++i) {
|
|
String expected = "pagelet postparam: postparam=";
|
|
expected += String(i);
|
|
expected += "pagelet getparam: ";
|
|
expected += String(i);
|
|
expected += "pagelet header: ";
|
|
expected += String(i);
|
|
|
|
// A timeout of 0 indicates an infinite timeout that blocks.
|
|
Variant code, headers;
|
|
VS(expected, f_pagelet_server_task_result(tasks[i], ref(headers),
|
|
ref(code), 0));
|
|
VS(code, 200);
|
|
VS(headers[1], "ResponseHeader: okay");
|
|
|
|
VS(expected, f_pagelet_server_task_result(tasks[i], ref(headers),
|
|
ref(code), 1));
|
|
VS(code, 200);
|
|
}
|
|
|
|
return Count(true);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool TestExtServer::test_xbox_send_message() {
|
|
static const StaticString
|
|
s_code("code"),
|
|
s_response("response");
|
|
Variant ret;
|
|
VERIFY(f_xbox_send_message("hello", ref(ret), 5000));
|
|
VS(ret[s_code], 200);
|
|
VS(ret[s_response], "olleh");
|
|
return Count(true);
|
|
}
|
|
|
|
bool TestExtServer::test_xbox_post_message() {
|
|
VERIFY(f_xbox_post_message("hello"));
|
|
return Count(true);
|
|
}
|
|
|
|
bool TestExtServer::test_xbox_task_start() {
|
|
// tested in test_xbox_task_result()
|
|
return Count(true);
|
|
}
|
|
|
|
bool TestExtServer::test_xbox_task_status() {
|
|
// tested in test_xbox_task_result()
|
|
return Count(true);
|
|
}
|
|
|
|
bool TestExtServer::test_xbox_task_result() {
|
|
Resource task = f_xbox_task_start("hello");
|
|
f_xbox_task_status(task);
|
|
Variant ret;
|
|
VS(f_xbox_task_result(task, 0, ref(ret)), 200);
|
|
VS(ret, "olleh");
|
|
return Count(true);
|
|
}
|