From 743cf336167f5ba7947b61c0cb94216b514c87f5 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 3 Feb 2018 18:02:57 +0100 Subject: [PATCH] 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. Backport-PR-URL: https://github.com/nodejs/node/pull/18957 PR-URL: https://github.com/nodejs/node/pull/18558 Reviewed-By: Ben Noordhuis --- test/cctest/node_test_fixture.cc | 5 ++++- test/cctest/node_test_fixture.h | 37 ++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/test/cctest/node_test_fixture.cc b/test/cctest/node_test_fixture.cc index 477adb5711af38..e4675c5db3c9f9 100644 --- a/test/cctest/node_test_fixture.cc +++ b/test/cctest/node_test_fixture.cc @@ -1,3 +1,6 @@ #include "node_test_fixture.h" -uv_loop_t current_loop; +uv_loop_t NodeTestFixture::current_loop; +std::unique_ptr NodeTestFixture::platform; +std::unique_ptr NodeTestFixture::allocator; +v8::Isolate::CreateParams NodeTestFixture::params; diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index ae9ec32e1ee9e4..5080f0334808eb 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -52,42 +52,47 @@ struct Argv { int nr_args_; }; -extern uv_loop_t current_loop; class NodeTestFixture : public ::testing::Test { public: static uv_loop_t* CurrentLoop() { return ¤t_loop; } - node::MultiIsolatePlatform* Platform() const { return platform_; } + node::MultiIsolatePlatform* Platform() const { return platform.get(); } protected: + static std::unique_ptr allocator; + static std::unique_ptr 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)); + allocator.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator()); + params.array_buffer_allocator = allocator.get(); CHECK_EQ(0, uv_loop_init(¤t_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_); } - virtual void TearDown() { - platform_->Shutdown(); + static void TearDownTestCase() { + platform->Shutdown(); while (uv_loop_alive(¤t_loop)) { uv_run(¤t_loop, UV_RUN_ONCE); } v8::V8::ShutdownPlatform(); - delete platform_; - platform_ = nullptr; CHECK_EQ(0, uv_loop_close(¤t_loop)); } - private: - node::NodePlatform* platform_ = nullptr; - std::unique_ptr allocator_{ - v8::ArrayBuffer::Allocator::NewDefaultAllocator()}; + virtual void SetUp() { + isolate_ = v8::Isolate::New(params); + CHECK_NE(isolate_, nullptr); + } + + virtual void TearDown() { + isolate_->Dispose(); + isolate_ = nullptr; + } }; #endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_