-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
test: introduce SetUpTestCase/TearDownTestCase #18558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
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.
- Loading branch information
commit 5f364eef53dcadddcccdaa521844b202a2140082
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,49 +53,45 @@ 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_; } | ||
|
|
||
| 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(8, 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(¤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_); | ||
|
|
||
| // 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(¤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<v8::ArrayBuffer::Allocator> allocator_{ | ||
| v8::ArrayBuffer::Allocator::NewDefaultAllocator()}; | ||
| virtual void SetUp() { | ||
| isolate_ = v8::Isolate::New(params); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing, I'll add the check. Thanks |
||
| } | ||
|
|
||
| virtual void TearDown() { | ||
| isolate_->Dispose(); | ||
| isolate_ = nullptr; | ||
| } | ||
| }; | ||
|
|
||
|
|
||
|
|
@@ -112,8 +108,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_, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe lower this to one to make the tests more deterministic.
As well, different cctests can (at least in theory) run concurrently; you don't want to have an explosion of threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I'll change it to 4.