Sha256: e021a992b8894155d1c8c8b2293a68b5c386be8023dee333fe8dba881697ceb7

Contents?: true

Size: 958 Bytes

Versions: 4

Compression:

Stored size: 958 Bytes

Contents

require_relative 'em_test_helper'

class TestSomeExceptions < Test::Unit::TestCase
  class DoomedConnectionError < StandardError
  end
  class DoomedConnection < EventMachine::Connection
    def unbind
      raise DoomedConnectionError
    end
  end

  # Read the commentary in EM#run.
  # This test exercises the ensure block in #run that makes sure
  # EM#release_machine gets called even if an exception is
  # thrown within the user code. Without the ensured call to release_machine,
  # the second call to EM#run will fail with a C++ exception
  # because the machine wasn't cleaned up properly.

  def test_a
    assert_raises(RuntimeError) {
      EM.run { raise "some exception" }
    }
  end

  def test_b
    assert_raises(RuntimeError) {
      EM.run { raise "some exception" }
    }
  end

  def test_exception_on_unbind
    assert_raises(DoomedConnectionError) {
      EM.run { EM.connect("localhost", 8888, DoomedConnection) }
    }
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
eventmachine-mkroman-1.3.0.dev.1 tests/test_exc.rb
wj_eventmachine-1.3.2 tests/test_exc.rb
wj_eventmachine-1.3.1 tests/test_exc.rb
wj_eventmachine-1.3.0.dev.1 tests/test_exc.rb