Sha256: 26b7531c20f9d1361d4e8bbc0587890ec204ff0cfb91608d698719f668e3248e

Contents?: true

Size: 832 Bytes

Versions: 3

Compression:

Stored size: 832 Bytes

Contents

#!/usr/bin/env ruby
# Test thread safety
require File.expand_path("../test_helper", __FILE__)
require "test/unit"
require "dbus"

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

3 entries across 3 versions & 1 rubygems

Version Path
ruby-dbus-0.10.0 test/thread_safety_test.rb
ruby-dbus-0.9.3 test/thread_safety_test.rb
ruby-dbus-0.9.2 test/thread_safety_test.rb