summaryrefslogtreecommitdiff
path: root/test/cctest
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2018-02-03 18:02:57 +0100
committerDaniel Bevenius <daniel.bevenius@gmail.com>2018-02-06 06:50:14 +0100
commitc64e130913a4c1a65b35253fcacf942fc5389223 (patch)
tree0d440b025014e2dff8657d3a7c44cf2350bf0ede /test/cctest
parent329fc78e4919231bf76771797878f7b0db0f73ac (diff)
downloadandroid-node-v8-c64e130913a4c1a65b35253fcacf942fc5389223.tar.gz
android-node-v8-c64e130913a4c1a65b35253fcacf942fc5389223.tar.bz2
android-node-v8-c64e130913a4c1a65b35253fcacf942fc5389223.zip
test: introduce SetUpTestCase/TearDownTestCase
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. PR-URL: https://github.com/nodejs/node/pull/18558 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/cctest')
-rw-r--r--test/cctest/node_test_fixture.cc6
-rw-r--r--test/cctest/node_test_fixture.h55
2 files changed, 31 insertions, 30 deletions
diff --git a/test/cctest/node_test_fixture.cc b/test/cctest/node_test_fixture.cc
index 477adb5711..3e5a112240 100644
--- a/test/cctest/node_test_fixture.cc
+++ b/test/cctest/node_test_fixture.cc
@@ -1,3 +1,7 @@
#include "node_test_fixture.h"
-uv_loop_t current_loop;
+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;
diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h
index 48642d5949..eaa4aaecdf 100644
--- a/test/cctest/node_test_fixture.h
+++ b/test/cctest/node_test_fixture.h
@@ -53,49 +53,46 @@ struct Argv {
int nr_args_;
};
-extern uv_loop_t current_loop;
class NodeTestFixture : public ::testing::Test {
- public:
- static uv_loop_t* CurrentLoop() { return &current_loop; }
-
- node::MultiIsolatePlatform* Platform() const { return platform_; }
-
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_;
- virtual void SetUp() {
+ 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));
- platform_ = new node::NodePlatform(8, nullptr);
- v8::V8::InitializePlatform(platform_);
+ v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
- v8::Isolate::CreateParams params_;
- params_.array_buffer_allocator = allocator_.get();
- isolate_ = v8::Isolate::New(params_);
-
- // 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());
- }
}
- virtual void TearDown() {
- platform_->Shutdown();
+ static void TearDownTestCase() {
+ platform->Shutdown();
while (uv_loop_alive(&current_loop)) {
uv_run(&current_loop, UV_RUN_ONCE);
}
v8::V8::ShutdownPlatform();
- delete platform_;
- platform_ = nullptr;
CHECK_EQ(0, uv_loop_close(&current_loop));
}
- private:
- node::NodePlatform* platform_ = nullptr;
- std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{
- v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
+ virtual void SetUp() {
+ isolate_ = v8::Isolate::New(params);
+ CHECK_NE(isolate_, nullptr);
+ }
+
+ virtual void TearDown() {
+ isolate_->Dispose();
+ isolate_ = nullptr;
+ }
};
@@ -112,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_,