Skip to content

Commit 22b8f9f

Browse files
danbevMylesBorins
authored andcommitted
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: #19504 PR-URL: #18558 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 36f664e commit 22b8f9f

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

test/cctest/node_test_fixture.cc

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
uv_loop_t NodeTestFixture::current_loop;
44
std::unique_ptr<node::NodePlatform> NodeTestFixture::platform;
55
std::unique_ptr<v8::ArrayBuffer::Allocator> NodeTestFixture::allocator;
6+
std::unique_ptr<v8::TracingController> NodeTestFixture::tracing_controller;
67
v8::Isolate::CreateParams NodeTestFixture::params;

test/cctest/node_test_fixture.h

+6-14
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,24 @@ struct Argv {
5555

5656

5757
class NodeTestFixture : public ::testing::Test {
58-
public:
59-
static uv_loop_t* CurrentLoop() { return &current_loop; }
60-
61-
node::MultiIsolatePlatform* Platform() const { return platform.get(); }
62-
6358
protected:
6459
static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator;
60+
static std::unique_ptr<v8::TracingController> tracing_controller;
6561
static std::unique_ptr<node::NodePlatform> platform;
6662
static v8::Isolate::CreateParams params;
6763
static uv_loop_t current_loop;
6864
v8::Isolate* isolate_;
6965

7066
static void SetUpTestCase() {
7167
platform.reset(new node::NodePlatform(4, nullptr));
68+
tracing_controller.reset(new v8::TracingController());
7269
allocator.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator());
7370
params.array_buffer_allocator = allocator.get();
71+
node::tracing::TraceEventHelper::SetTracingController(
72+
tracing_controller.get());
7473
CHECK_EQ(0, uv_loop_init(&current_loop));
7574
v8::V8::InitializePlatform(platform.get());
7675
v8::V8::Initialize();
77-
78-
// As the TracingController is stored globally, we only need to create it
79-
// one time for all tests.
80-
if (node::tracing::TraceEventHelper::GetTracingController() == nullptr) {
81-
node::tracing::TraceEventHelper::SetTracingController(
82-
new v8::TracingController());
83-
}
8476
}
8577

8678
static void TearDownTestCase() {
@@ -117,8 +109,8 @@ class EnvironmentTestFixture : public NodeTestFixture {
117109
context_->Enter();
118110

119111
isolate_data_ = node::CreateIsolateData(isolate,
120-
NodeTestFixture::CurrentLoop(),
121-
test_fixture->Platform());
112+
&NodeTestFixture::current_loop,
113+
platform.get());
122114
CHECK_NE(nullptr, isolate_data_);
123115
environment_ = node::CreateEnvironment(isolate_data_,
124116
context_,

0 commit comments

Comments
 (0)