Skip to content

Commit

Permalink
test: introduce SetUpTestCase/TearDownTestCase
Browse files Browse the repository at this point in the history
This commit add SetUpTestCase and TearDownTestCase functions that will
be called once per test case. Currently we only have SetUp/TearDown
which are called for each test.

This commit moves the initialization and configuration of Node and V8 to
be done on a per test case basis, but gives each test a new Isolate.

Backport-PR-URL: #19504
PR-URL: #18558
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
danbev authored and MylesBorins committed Mar 21, 2018
1 parent 36f664e commit 22b8f9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
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;
20 changes: 6 additions & 14 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 @@ -117,8 +109,8 @@ class EnvironmentTestFixture : public NodeTestFixture {
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

0 comments on commit 22b8f9f

Please sign in to comment.