Skip to content

Commit 743cf33

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: #18957 PR-URL: #18558 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 684684e commit 743cf33

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

test/cctest/node_test_fixture.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#include "node_test_fixture.h"
22

3-
uv_loop_t current_loop;
3+
uv_loop_t NodeTestFixture::current_loop;
4+
std::unique_ptr<node::NodePlatform> NodeTestFixture::platform;
5+
std::unique_ptr<v8::ArrayBuffer::Allocator> NodeTestFixture::allocator;
6+
v8::Isolate::CreateParams NodeTestFixture::params;

test/cctest/node_test_fixture.h

+21-16
Original file line numberDiff line numberDiff line change
@@ -52,42 +52,47 @@ struct Argv {
5252
int nr_args_;
5353
};
5454

55-
extern uv_loop_t current_loop;
5655

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

61-
node::MultiIsolatePlatform* Platform() const { return platform_; }
60+
node::MultiIsolatePlatform* Platform() const { return platform.get(); }
6261

6362
protected:
63+
static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator;
64+
static std::unique_ptr<node::NodePlatform> platform;
65+
static v8::Isolate::CreateParams params;
66+
static uv_loop_t current_loop;
6467
v8::Isolate* isolate_;
6568

66-
virtual void SetUp() {
69+
static void SetUpTestCase() {
70+
platform.reset(new node::NodePlatform(4, nullptr));
71+
allocator.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator());
72+
params.array_buffer_allocator = allocator.get();
6773
CHECK_EQ(0, uv_loop_init(&current_loop));
68-
platform_ = new node::NodePlatform(8, nullptr);
69-
v8::V8::InitializePlatform(platform_);
74+
v8::V8::InitializePlatform(platform.get());
7075
v8::V8::Initialize();
71-
v8::Isolate::CreateParams params_;
72-
params_.array_buffer_allocator = allocator_.get();
73-
isolate_ = v8::Isolate::New(params_);
7476
}
7577

76-
virtual void TearDown() {
77-
platform_->Shutdown();
78+
static void TearDownTestCase() {
79+
platform->Shutdown();
7880
while (uv_loop_alive(&current_loop)) {
7981
uv_run(&current_loop, UV_RUN_ONCE);
8082
}
8183
v8::V8::ShutdownPlatform();
82-
delete platform_;
83-
platform_ = nullptr;
8484
CHECK_EQ(0, uv_loop_close(&current_loop));
8585
}
8686

87-
private:
88-
node::NodePlatform* platform_ = nullptr;
89-
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{
90-
v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
87+
virtual void SetUp() {
88+
isolate_ = v8::Isolate::New(params);
89+
CHECK_NE(isolate_, nullptr);
90+
}
91+
92+
virtual void TearDown() {
93+
isolate_->Dispose();
94+
isolate_ = nullptr;
95+
}
9196
};
9297

9398
#endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_

0 commit comments

Comments
 (0)