Uncaught exception in client code does not release contextReference object in ScenarioScope
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- cpp
- Lĩnh vực
- testing-qa
Hướng nghiên cứu
Bắt đầu với CukeCommands::endScenario và lần theo HookRegistrar::execAfterHooks, contextManager.purgeContexts và currentScenario.reset(). So sánh cách xử lý hook với BasicStep::invoke. Hoàn thành khi một exception từ hook AFTER vẫn giải phóng context của scenario và các scenario về sau vẫn được cô lập, trong khi lỗi của hook được báo cáo thay vì xuất hiện dưới dạng lỗi wire-server không liên quan.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When the test client code has a function call inside After step and this function call throws an exception, then cucumber-cpp does not catch this error on server side thus yields undefined behavior. This uncaught exception causes endScenario() function abort and won't release the current scenario scope from memory. This impacts all the scenarios after this and causes undefined method '[]' for nil:NilClass (NoMethodError) error in the wire server. It seems the uncaught exception goes straight into the parser and shadows the real problem.
Expected Behavior
Every each test scenario should be isolated from each other scenario and the hooks should also handle any possible exception to ensure the test scenario remains in stable state. Cucumber should manage the lifetime of the scenario object properly and it should release its resources even if an exception is thrown in the client side.
Current Behavior
The wire server does not support responses on hooks at the moment. If there is an uncaught exception in the after step for example, then the uncaught exception impacts the current test scenario. The endScenario() function stops abruptly without releasing its resources.
The below error message is shown in the console when there is an exception in after step:
undefined method `[]' for nil:NilClass (NoMethodError)
Possible Solution
The endScenario should release the resources of the current scenario even if an exception occurs. A try... catch block should do the trick in this code block like this:
void CukeCommands::endScenario() {
std::exception_ptr eptr;
try {
HookRegistrar::execAfterHooks(currentScenario.get());
} catch (...) {
eptr = std::current_exception();
}
contextManager.purgeContexts();
currentScenario.reset();
if (eptr != nullptr) {
std::rethrow_exception(eptr);
}
}
This fix on its own would not fix the problem altogether however... The Hook object should also implement methods that communicates with the wire server and reports any possible errors that might occur. The Hook class should have similar behavior as BasicStep and it should return the InvokeResult accordingly.
InvokeResult BasicStep::invoke(const InvokeArgs *pArgs) {
this->pArgs = pArgs;
currentArgIndex = 0;
currentResult = InvokeResult::success();
try {
InvokeResult returnedResult = invokeStepBody();
if (currentResult.isPending()) {
return currentResult;
} else {
return returnedResult;
}
} catch (const std::exception& ex) {
return InvokeResult::failure(ex.what());
} catch (const std::string& ex) {
return InvokeResult::failure(ex);
} catch (const char *ex) {
return InvokeResult::failure(ex);
} catch (...) {
// Cucumber needs a description here
return InvokeResult::failure("Unknown exception");
}
}
Steps to Reproduce (for bugs)
- In your test code, create an AFTER() step.
- Place a simple throw -1 inside it.
- See what happens.
Context & Motivation
We are using cucumber-cpp to test the behavior of our product.
Your Environment
- Version used: 0.4
- Operating System and version: Windows 10
- Ngôn ngữ chính
- C++
- Star
- 330
- Fork
- 142
- Merge trung bình
- 2 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cucumber/cucumber-cpp
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
cucumber/cucumber-cpp#317 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
cucumber/cucumber-cpp#313 · 9 bình luận ·
-
Authorize hyphen "-" for TagCó thể làm lại được @ursfassler đã nhận 399 ngày trước và không có pull request nào đang mở. Đang mởbug
cucumber/cucumber-cpp#312 · 4 bình luận · 1 người được giao ·
-
feature
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
cucumber/cucumber-cpp#304 · 2 bình luận ·
-
Cucumber for MakefileĐang mởhelp
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
cucumber/cucumber-cpp#302 · 1 bình luận ·
Tất cả issue của cucumber/cucumber-cpp
Issue tương tự
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
cloudflare/workerd#8963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Android Bug Core Drape
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
organicmaps/organicmaps#14449 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
comp-codecs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ClickHouse/ClickHouse#135159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[raygui] update to 5.0Đang mởcategory:port-update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 2 ngày
-
difficulty:easy func:python os:windows prio:high type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NatronGitHub/Natron#2029 ·
Maintainer thường phản hồi trong vòng 1 ngày