Module: Bitfab::ReplayContext

Defined in:
lib/bitfab/replay.rb

Overview

Thread-local replay context management.

Class Method Summary collapse

Class Method Details

.currentObject



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, 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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bitfab/replay.rb', line 25

def with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, 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:,
    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