File: test_hash.rb

package info (click to toggle)
ruby-thread-safe 0.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 700 kB
  • ctags: 1,072
  • sloc: java: 5,458; ruby: 2,750; makefile: 2
file content (20 lines) | stat: -rw-r--r-- 430 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require 'test/unit'
require 'thread_safe'

class TestHash < Test::Unit::TestCase
  def test_concurrency
    pend if RUBY_VERSION =~ /2\.0/
    hsh = ThreadSafe::Hash.new
    assert_nothing_raised do
      (1..100).map do |i|
        Thread.new do
          1000.times do |j|
            hsh[i*1000+j] = i
            hsh[i*1000+j]
            hsh.delete(i*1000+j)
          end
        end
      end.map(&:join)
    end
  end
end