Module: Bitfab::ReplayContext
- Defined in:
- lib/bitfab/replay.rb
Overview
Thread-local replay context management.
Class Method Summary collapse
- .current ⇒ Object
-
.with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, mock_tree: nil, mock_strategy: nil) ⇒ Object
Execute a block with replay context set on the current thread.
Class Method Details
.current ⇒ Object
19 20 21 |
# File 'lib/bitfab/replay.rb', line 19 def current Thread.current[REPLAY_CONTEXT_KEY] end |
.with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, mock_tree: nil, mock_strategy: nil) ⇒ Object
Execute a block with replay context set on the current thread. The context is automatically cleared when the block completes.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bitfab/replay.rb', line 31 def with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, mock_tree: nil, mock_strategy: nil) previous = Thread.current[REPLAY_CONTEXT_KEY] ctx = { test_run_id:, input_source_span_id:, input_source_trace_id: } if mock_tree ctx[:mock_tree] = mock_tree ctx[:mock_strategy] = mock_strategy || "none" ctx[:call_counters] = {} end Thread.current[REPLAY_CONTEXT_KEY] = ctx yield ensure Thread.current[REPLAY_CONTEXT_KEY] = previous end |