Exceptions can be hard to catch in test environments
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
Hướng nghiên cứu
Bắt đầu từ lib/temporal/workflow.rb, ở quanh phần rescue StandardError, và theo dõi cách Temporal::Testing.local! thực thi các workflow. Tái hiện ví dụ thiếu keyword, sau đó xác định và ghi lại một hành vi của việc kiểm thử cục bộ trong đó các exception của workflow được hiển thị mà không thay đổi cách xử lý workflow thông thường; được xem là hoàn tất khi test hiển thị exception cùng một stack trace hữu ích.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Cool library, and thank you for your hard work on it! I'm trying to help improve it through this feedback, and would be willing to open a PR if there's guidance provided on desirable compromises or solutions.
The way that Temporal::Workflow rescues StandardError makes catching exceptions in tests hard.
Take this spec as an example:
$global_var = 0
class HelloWorldWorkflow < Temporal::Workflow
def execute(arg1, required_key:)
$global_var += 1
nil
end
end
describe HelloWorldWorkflow do
it "doesn't allow exceptions to surface very easily" do
Temporal::Testing.local! do
Temporal.start_workflow(HelloWorldWorkflow, "foo", required_key: "bar")
expect($global_var).to eq(1)
Temporal.start_workflow(HelloWorldWorkflow, "foo") # incorrect arguments
expect($global_var).to eq(2)
end
end
end
The result is:
expected: 2
got: 1
(compared using ==)
Yes, I can see in the logs that an exception is logged, but I feel like in tests raising exceptions should be the rule. Any number of things can break downstream within a workflow, and sometimes (when not directly testing the unit that is the workflow) it's useful to call a thing, and not have to make an assertion that it didn't log an exception -- if that makes sense. Rescuing StandardError is heavy handed in the tests, because allowing those to raise is way more useful in identifying any issues.
To address this I've wrapped the base class with my own, so I can re-raise the exception in a way that Temporal doesn't try to handle. I'm wondering if Temporal::Testing should take this into consideration and not rescue any exceptions when executing the workflow locally in tests.
class ApplicationWorkflow < Temporal::Workflow
def execute(*args, **kwargs)
perform(*args, **kwargs)
rescue => e
raise(Exception, e.message) if defined?(Temporal::Testing) && Temporal::Testing.local?
raise(e)
end
end
class HelloWorldWorkflow < ApplicationWorkflow
def perform(arg1, required_key:)
$global_var += 1
nil
end
end
And the more useful result now includes the exception and stops the execution of the spec, which is what would be most helpful.
Exception: missing keyword: :required_key
It's still not the best solution though because it now has two rescues and pollutes the stack trace.
- Ngôn ngữ chính
- Ruby
- Star
- 288
- Fork
- 113
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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 coinbase/temporal-ruby
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
coinbase/temporal-ruby#361 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
coinbase/temporal-ruby#341 ·
-
Emitting Metrics for PrometheusĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
coinbase/temporal-ruby#328 · 1 bình luận ·
-
NoMethodError when await_workflow_result is called for long running workflowsCó thể đã có người làm @iekundayo đã nhận 707 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
coinbase/temporal-ruby#326 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
coinbase/temporal-ruby#324 · 3 bình luận · 2 reaction ·
Tất cả issue của coinbase/temporal-ruby
Issue tương tự
-
Add Nagoya Ruby Kaigi 05Đang mởcontent good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
rubyevents/rubyevents#2182 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Homebrew/homebrew-cask#293134 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
notch8/iiif_print#430 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày