Class: AMQP::SpecHelper::AMQPExample

Inherits:
EventedExample show all
Defined in:
lib/amqp-spec/evented_example.rb

Overview

Represents spec running inside AMQP.start loop

Instance Method Summary collapse

Methods inherited from EventedExample

#finish_em_loop, #initialize, #run_em_hooks, #run_em_loop, #timeout

Constructor Details

This class inherits a constructor from AMQP::SpecHelper::EventedExample

Instance Method Details

#done(delay = nil) ⇒ Object

Breaks the event loop and finishes the spec. It yields to any given block first, then stops AMQP, EM event loop and cleans up AMQP state.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/amqp-spec/evented_example.rb', line 135

def done(delay = nil)
  super(delay) do
    yield if block_given?
    EM.next_tick do
      run_em_hooks :amqp_after
      if AMQP.conn and not AMQP.closing
        AMQP.stop_connection do
          AMQP.cleanup_state
          finish_em_loop
        end
      else
        AMQP.cleanup_state
        finish_em_loop
      end
    end
  end
end

#finish_exampleObject

Called from run_event_loop when event loop is finished, before any exceptions is raised or example returns. We ensure AMQP state cleanup here.



155
156
157
158
# File 'lib/amqp-spec/evented_example.rb', line 155

def finish_example
  AMQP.cleanup_state
  super
end

#runObject

Run @block inside the AMQP.start loop



123
124
125
126
127
128
129
130
# File 'lib/amqp-spec/evented_example.rb', line 123

def run
  run_em_loop do
    AMQP.start_connection(@opts) do
      run_em_hooks :amqp_before
      @block.call
    end
  end
end