Sha256: e7cb3496d6598cc7e604bb99fb8a8ce39adca08aed5a9d2a6244bc9844937038

Contents?: true

Size: 782 Bytes

Versions: 5

Compression:

Stored size: 782 Bytes

Contents

#!/usr/bin/env rspec
# Test thread safety
require_relative "spec_helper"
require "dbus"

describe "ThreadSafetyTest" do
  it "tests thread competition" do
    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
          expect(obj.the_answer[0]).to eq(42)
          sleep 0.1 * rand
        end
      end
    end
    jobs.each do |thread| thread.join end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ruby-dbus-0.12.0 spec/thread_safety_spec.rb
ruby-dbus-0.11.2 spec/thread_safety_spec.rb
ruby-dbus-0.11.1 spec/thread_safety_spec.rb
em-ruby-dbus-0.11.0 test/thread_safety_spec.rb
ruby-dbus-0.11.0 test/thread_safety_spec.rb