Sha256: d748664653ba39392bfbc350f3a822664ef08f41073d982058143f17ae27a6e4

Contents?: true

Size: 884 Bytes

Versions: 14

Compression:

Stored size: 884 Bytes

Contents

require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )

require 'hitimes'
require 'hitimes/mutexed_stats'

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

  it "is unsafe normally" do
    pending "not for MRI -- not interruptable in this C extension" do
      stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
      stats.count.should_not == @final_value
    end
  end

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

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hitimes-1.1.1-java spec/mutex_stats_spec.rb
hitimes-1.1.1-x86-mswin32 spec/mutex_stats_spec.rb
hitimes-1.1.1-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.1.1 spec/mutex_stats_spec.rb
hitimes-1.1.0-java spec/mutex_stats_spec.rb
hitimes-1.1.0-x86-mswin32 spec/mutex_stats_spec.rb
hitimes-1.1.0-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.1.0 spec/mutex_stats_spec.rb
hitimes-1.0.5-x86-mswin32 spec/mutex_stats_spec.rb
hitimes-1.0.5-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.0.5 spec/mutex_stats_spec.rb
hitimes-1.0.4-x86-mswin32 spec/mutex_stats_spec.rb
hitimes-1.0.4-x86-mingw32 spec/mutex_stats_spec.rb
hitimes-1.0.4 spec/mutex_stats_spec.rb