Sha256: 84b62b095e2a88bdc49a236dcfe7de35bb9f7e279ad9eea679936ad02e407ab1

Contents?: true

Size: 951 Bytes

Versions: 29

Compression:

Stored size: 951 Bytes

Contents

require 'spec_helper'

describe Hitimes::MutexedStats do
  before( :each ) do
    @threads = 5
    @iters   = 10_000
    @final_value = @threads * @iters
  end

  def run_with_scissors( stats, threads, iters )
    spool = []
    threads.times do |t|
      spool << Thread.new { iters.times{ stats.update( 1 ) } }
    end
    spool.each { |t| t.join }
    return stats
  end

  if (not defined? RUBY_ENGINE) or (RUBY_ENGINE == "ruby") then
    it "Hitimes::Stats is threadsafe" do
      stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
      stats.count.must_equal @final_value
    end
  else
    it "Hitimes::Stats is not threadsafe" do
      stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
      stats.count.wont_equal @final_value
    end
  end

  it "has a threadsafe update" do
    stats = run_with_scissors( ::Hitimes::MutexedStats.new, @threads, @iters )
    stats.count.must_equal @final_value
  end

end

Version data entries

29 entries across 27 versions & 4 rubygems

Version Path
hitimes-1.3.1-x64-mingw32 spec/mutex_stats_spec.rb
hitimes-1.3.1-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.3.1-java spec/mutex_stats_spec.rb
hitimes-1.3.1 spec/mutex_stats_spec.rb
hitimes-1.3.0-x64-mingw32 spec/mutex_stats_spec.rb
hitimes-1.3.0-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.3.0-java spec/mutex_stats_spec.rb
hitimes-1.3.0 spec/mutex_stats_spec.rb
hitimes-1.2.6-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.2.6-java spec/mutex_stats_spec.rb
hitimes-1.2.6 spec/mutex_stats_spec.rb
hitimes-1.2.5-java spec/mutex_stats_spec.rb
hitimes-1.2.5-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.2.5 spec/mutex_stats_spec.rb
hitimes-1.2.4-java spec/mutex_stats_spec.rb
hitimes-1.2.4-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.2.4 spec/mutex_stats_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/hitimes-1.2.2/spec/mutex_stats_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/hitimes-1.2.2/spec/mutex_stats_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/hitimes-1.2.2/spec/mutex_stats_spec.rb