Sha256: 852513d417bbf17d1b093edc18b6335d264a1b61401cfa2f14fb49eddd123853

Contents?: true

Size: 1.21 KB

Versions: 36

Compression:

Stored size: 1.21 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Threadsafe" do
  it "should be able to spawn threadsafe proxy-objects" do
    require "knjrbfw"
    
    arr = Knj::Threadsafe::Proxy.new(:obj => {})
    
    0.upto(5) do |i|
      arr[i] = i
    end
    
    Knj::Thread.new do
      arr.each do |key, val|
        res = key + val
        sleep 0.1
      end
    end
    
    5.upto(10) do |i|
      arr[i] = i
      sleep 0.1
    end
  end
  
  it "should be able to spawn special classes" do
    require "knjrbfw"
    
    #Create new synchronized hash.
    arr = Knj::Threadsafe::Synced_hash.new
    
    #Make sure we get the right results.
    arr[1] = 2
    
    res = arr[1]
    raise "Expected 2 but got '#{res}'." if res != 2
    
    #Set some values to test with.
    0.upto(5) do |i|
      arr[i] = i
    end
    
    #Try to call through each through a thread and then also try to set new values, which normally would crash the hash.
    Knj::Thread.new do
      arr.each do |key, val|
        res = key + val
        sleep 0.1
      end
    end
    
    #This should not crash it, since they should wait for each other.
    5.upto(10) do |i|
      arr[i] = i
      sleep 0.1
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
knjrbfw-0.0.68 spec/threadsafe_spec.rb
knjrbfw-0.0.67 spec/threadsafe_spec.rb
knjrbfw-0.0.66 spec/threadsafe_spec.rb
knjrbfw-0.0.65 spec/threadsafe_spec.rb
knjrbfw-0.0.64 spec/threadsafe_spec.rb
knjrbfw-0.0.63 spec/threadsafe_spec.rb
knjrbfw-0.0.62 spec/threadsafe_spec.rb
knjrbfw-0.0.59 spec/threadsafe_spec.rb
knjrbfw-0.0.58 spec/threadsafe_spec.rb
knjrbfw-0.0.57 spec/threadsafe_spec.rb
knjrbfw-0.0.55 spec/threadsafe_spec.rb
knjrbfw-0.0.54 spec/threadsafe_spec.rb
knjrbfw-0.0.53 spec/threadsafe_spec.rb
knjrbfw-0.0.52 spec/threadsafe_spec.rb
knjrbfw-0.0.51 spec/threadsafe_spec.rb
knjrbfw-0.0.50 spec/threadsafe_spec.rb
knjrbfw-0.0.49 spec/threadsafe_spec.rb
knjrbfw-0.0.48 spec/threadsafe_spec.rb
knjrbfw-0.0.47 spec/threadsafe_spec.rb
knjrbfw-0.0.46 spec/threadsafe_spec.rb