Class: CrossSpec::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/cross_spec/spec.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.trace(&block) ⇒ Object



48
49
50
51
52
53
# File 'lib/cross_spec/spec.rb', line 48

def self.trace(&block)
  spec = new
  DistributedTracing.trace do
    spec.instance_eval(&block)
  end
end

Instance Method Details

#async(service:, data: nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cross_spec/spec.rb', line 55

def async(service:, data: nil)
  DistributedTracing.trace do
    str = JSON.dump(
      service: service,
      biomarkers: DistributedTracing.get,
      data: data
    )
    CrossSpec.broadcast(str)
  end
  nil
end

#await(tasks:, options: {}, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cross_spec/spec.rb', line 72

def await(tasks:, options: {}, &block)
  combined = { timeout: 5 }.merge(options)
  waiting = SpecWaiting.new(tasks)
  ::Timeout::timeout(combined[:timeout]) do
    CrossSpec.listen! do |message|
      waiting.process(message, &block)
      return waiting.data.length == 1 ? waiting.data.first : waiting.data if waiting.done?
      nil # nil keeps blocking listen!
    end
  end
end

#sync(service:, data: nil, tasks:, options: {}, &block) ⇒ Object



67
68
69
70
# File 'lib/cross_spec/spec.rb', line 67

def sync(service:, data: nil, tasks:, options: {}, &block)
  async(service: service, data: data)
  await(tasks: tasks, options: options, &block)
end