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

Parameters:

  • test_run_id (String)
  • input_source_span_id (String, nil) (defaults to: nil)
  • input_source_trace_id (String, nil) (defaults to: nil)
  • mock_tree (Hash{String => Hash}, nil) (defaults to: nil)

    keyed by “#key:#index”

  • mock_strategy (String, nil) (defaults to: nil)

    one of MOCK_STRATEGIES



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