Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9.x backport] test: introduce SetUpTestCase/TearDownTestCase #19504

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/cctest/node_test_fixture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
uv_loop_t NodeTestFixture::current_loop;
std::unique_ptr<node::NodePlatform> NodeTestFixture::platform;
std::unique_ptr<v8::ArrayBuffer::Allocator> NodeTestFixture::allocator;
std::unique_ptr<v8::TracingController> NodeTestFixture::tracing_controller;
v8::Isolate::CreateParams NodeTestFixture::params;
24 changes: 7 additions & 17 deletions test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,24 @@ struct Argv {


class NodeTestFixture : public ::testing::Test {
public:
static uv_loop_t* CurrentLoop() { return &current_loop; }

node::MultiIsolatePlatform* Platform() const { return platform.get(); }

protected:
static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator;
static std::unique_ptr<v8::TracingController> tracing_controller;
static std::unique_ptr<node::NodePlatform> platform;
static v8::Isolate::CreateParams params;
static uv_loop_t current_loop;
v8::Isolate* isolate_;

static void SetUpTestCase() {
platform.reset(new node::NodePlatform(4, nullptr));
tracing_controller.reset(new v8::TracingController());
allocator.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator());
params.array_buffer_allocator = allocator.get();
node::tracing::TraceEventHelper::SetTracingController(
tracing_controller.get());
CHECK_EQ(0, uv_loop_init(&current_loop));
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();

// As the TracingController is stored globally, we only need to create it
// one time for all tests.
if (node::tracing::TraceEventHelper::GetTracingController() == nullptr) {
node::tracing::TraceEventHelper::SetTracingController(
new v8::TracingController());
}
}

static void TearDownTestCase() {
Expand Down Expand Up @@ -108,17 +100,15 @@ class EnvironmentTestFixture : public NodeTestFixture {
public:
class Env {
public:
Env(const v8::HandleScope& handle_scope,
const Argv& argv,
NodeTestFixture* test_fixture) {
Env(const v8::HandleScope& handle_scope, const Argv& argv) {
auto isolate = handle_scope.GetIsolate();
context_ = node::NewContext(isolate);
CHECK(!context_.IsEmpty());
context_->Enter();

isolate_data_ = node::CreateIsolateData(isolate,
NodeTestFixture::CurrentLoop(),
test_fixture->Platform());
&NodeTestFixture::current_loop,
platform.get());
CHECK_NE(nullptr, isolate_data_);
environment_ = node::CreateEnvironment(isolate_data_,
context_,
Expand Down
8 changes: 4 additions & 4 deletions test/cctest/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EnvironmentTest : public EnvironmentTestFixture {
TEST_F(EnvironmentTest, AtExitWithEnvironment) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env {handle_scope, argv, this};
Env env {handle_scope, argv};

AtExit(*env, at_exit_callback1);
RunAtExit(*env);
Expand All @@ -42,7 +42,7 @@ TEST_F(EnvironmentTest, AtExitWithEnvironment) {
TEST_F(EnvironmentTest, AtExitWithArgument) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env {handle_scope, argv, this};
Env env {handle_scope, argv};

std::string arg{"some args"};
AtExit(*env, at_exit_callback1, static_cast<void*>(&arg));
Expand All @@ -53,8 +53,8 @@ TEST_F(EnvironmentTest, AtExitWithArgument) {
TEST_F(EnvironmentTest, MultipleEnvironmentsPerIsolate) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env1 {handle_scope, argv, this};
Env env2 {handle_scope, argv, this};
Env env1 {handle_scope, argv};
Env env2 {handle_scope, argv};

AtExit(*env1, at_exit_callback1);
AtExit(*env2, at_exit_callback2);
Expand Down
10 changes: 5 additions & 5 deletions test/cctest/test_node_postmortem_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TEST_F(DebugSymbolsTest, ExternalStringDataOffset) {
TEST_F(DebugSymbolsTest, BaseObjectPersistentHandle) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env{handle_scope, argv, this};
Env env{handle_scope, argv};

v8::Local<v8::Object> object = v8::Object::New(isolate_);
node::BaseObject obj(*env, object);
Expand All @@ -87,7 +87,7 @@ TEST_F(DebugSymbolsTest, BaseObjectPersistentHandle) {
TEST_F(DebugSymbolsTest, EnvironmentHandleWrapQueue) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env{handle_scope, argv, this};
Env env{handle_scope, argv};

auto expected = reinterpret_cast<uintptr_t>((*env)->handle_wrap_queue());
auto calculated = reinterpret_cast<uintptr_t>(*env) +
Expand All @@ -98,7 +98,7 @@ TEST_F(DebugSymbolsTest, EnvironmentHandleWrapQueue) {
TEST_F(DebugSymbolsTest, EnvironmentReqWrapQueue) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env{handle_scope, argv, this};
Env env{handle_scope, argv};

auto expected = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue());
auto calculated = reinterpret_cast<uintptr_t>(*env) +
Expand All @@ -109,7 +109,7 @@ TEST_F(DebugSymbolsTest, EnvironmentReqWrapQueue) {
TEST_F(DebugSymbolsTest, HandleWrapList) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env{handle_scope, argv, this};
Env env{handle_scope, argv};

uv_tcp_t handle;

Expand Down Expand Up @@ -138,7 +138,7 @@ TEST_F(DebugSymbolsTest, HandleWrapList) {
TEST_F(DebugSymbolsTest, ReqWrapList) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env{handle_scope, argv, this};
Env env{handle_scope, argv};

auto obj_template = v8::FunctionTemplate::New(isolate_);
obj_template->InstanceTemplate()->SetInternalFieldCount(1);
Expand Down