Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Exceptions can be hard to catch in test environments

Đang mở
#197 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

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
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
backend, testing

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của coinbase/temporal-ruby

Tất cả issue của coinbase/temporal-ruby

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.