Sha256: cfe987a6724ca00941995b78fde8484334d8c179c3a7a5d5b53f6203d1917e02

Contents?: true

Size: 838 Bytes

Versions: 6

Compression:

Stored size: 838 Bytes

Contents

#!/usr/bin/env ruby
# Test thread safety
require "test/unit"
require "dbus-openplacos"

def d(msg)
  puts "#{$$} #{msg}" if $DEBUG
end

class ThreadSafetyTest < Test::Unit::TestCase
  def test_thread_competition
    print "Thread competition: "
    jobs = []
    5.times do
      jobs << Thread.new do
        Thread.current.abort_on_exception = true

        # use separate connections to avoid races
        bus = DBus::ASessionBus.new
        svc = bus.service("org.ruby.service")
        obj = svc.object("/org/ruby/MyInstance")
        obj.introspect
        obj.default_iface = "org.ruby.SampleInterface"

        10.times do |i|
          print "#{i} "
          $stdout.flush
          assert_equal 42, obj.the_answer[0]
          sleep 0.1 * rand
        end
      end
    end
    jobs.each do |thread| thread.join end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-dbus-openplacos-0.7.2.2 test/thread_safety_test.rb
ruby-dbus-openplacos-0.7.2.1 test/thread_safety_test.rb
ruby-dbus-openplacos-0.7.2 test/thread_safety_test.rb
ruby-dbus-openplacos-0.7.0 test/thread_safety_test.rb
ruby-dbus-openplacos-0.6.2 test/thread_safety_test.rb
ruby-dbus-openplacos-0.6.1 test/thread_safety_test.rb