Sha256: c5126eff419c8505c1223846b562db7372e15163e2fdb5d696b882e522f1529e

Contents?: true

Size: 739 Bytes

Versions: 6

Compression:

Stored size: 739 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.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(&:join)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-dbus-0.17.0 spec/thread_safety_spec.rb
ruby-dbus-0.16.0 spec/thread_safety_spec.rb
ruby-dbus-0.15.0 spec/thread_safety_spec.rb
ruby-dbus-0.14.1 spec/thread_safety_spec.rb
ruby-dbus-0.14.0 spec/thread_safety_spec.rb
ruby-dbus-0.13.0 spec/thread_safety_spec.rb