Sha256: fb9a1597334e19813d50e264b864193864447974360b310ab3b3b1fc73eb7280

Contents?: true

Size: 1014 Bytes

Versions: 40

Compression:

Stored size: 1014 Bytes

Contents

require 'em_test_helper'

class TestConnectionWrite < Test::Unit::TestCase

  # This test takes advantage of the fact that EM::_RunSelectOnce iterates over the connections twice:
  #   - once to determine which ones to call Write() on
  #   - and once to call Write() on each of them.
  #
  # But state may change in the meantime before Write() is finally called.
  # And that is what we try to exploit to get Write() to be called when bWatchOnly is true, and bNotifyWritable is false,
  # to cause an assertion failure.

  module SimpleClient
    def notify_writable
      $conn2.notify_writable = false  # Being naughty in callback
      # If this doesn't crash anything, the test passed!
    end
  end

  def test_with_naughty_callback
    EM.run do
      r1, _ = IO.pipe
      r2, _ = IO.pipe

      # Adding EM.watches
      $conn1 = EM.watch(r1, SimpleClient)
      $conn2 = EM.watch(r2, SimpleClient)

      $conn1.notify_writable = true
      $conn2.notify_writable = true

      EM.stop
    end
  end
end

Version data entries

40 entries across 37 versions & 4 rubygems

Version Path
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_connection_write.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/eventmachine-1.2.7/tests/test_connection_write.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/eventmachine-1.2.7/tests/test_connection_write.rb
eventmachine-1.2.7-java tests/test_connection_write.rb
eventmachine-1.2.7-x64-mingw32 tests/test_connection_write.rb
eventmachine-1.2.7-x86-mingw32 tests/test_connection_write.rb
eventmachine-1.2.7 tests/test_connection_write.rb
eventmachine-1.2.6-x64-mingw32 tests/test_connection_write.rb
eventmachine-1.2.6-x86-mingw32 tests/test_connection_write.rb
eventmachine-1.2.6-java tests/test_connection_write.rb
eventmachine-1.2.6 tests/test_connection_write.rb
eventmachine-1.2.5-x86-mingw32 tests/test_connection_write.rb
eventmachine-1.2.5-x64-mingw32 tests/test_connection_write.rb
eventmachine-1.2.5-java tests/test_connection_write.rb
eventmachine-1.2.5 tests/test_connection_write.rb
eventmachine-1.2.3-x64-mingw32 tests/test_connection_write.rb
eventmachine-1.2.3-x86-mingw32 tests/test_connection_write.rb
eventmachine-1.2.3-java tests/test_connection_write.rb
eventmachine-1.2.3 tests/test_connection_write.rb
eventmachine-1.2.2-java tests/test_connection_write.rb