thread_tools 0.23 → 0.24
Sign up to get free protection for your applications and to get access to all the features.
- data/test/test_debugmutex.rb +47 -0
- data/thread_tools.gemspec +3 -1
- metadata +3 -1
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.dirname(__FILE__)+'/../lib/thread_tools/debugmutex')
|
3
|
+
|
4
|
+
|
5
|
+
class DebugMutexTest < Test::Unit::TestCase
|
6
|
+
def test_lock_unlock_trylock
|
7
|
+
mtx = ThreadTools::DebugMutex.new
|
8
|
+
|
9
|
+
# lock should return self
|
10
|
+
assert_equal(mtx.lock, mtx)
|
11
|
+
# mutex should be locked
|
12
|
+
assert(mtx.locked?)
|
13
|
+
# unlock should return nil
|
14
|
+
assert_nil(mtx.unlock)
|
15
|
+
|
16
|
+
# try_lock should return true
|
17
|
+
assert(mtx.try_lock)
|
18
|
+
# try_lock should return false
|
19
|
+
assert(!mtx.try_lock)
|
20
|
+
|
21
|
+
mtx.unlock
|
22
|
+
# unlock should raise if not locked
|
23
|
+
assert_raise ThreadError do
|
24
|
+
mtx.unlock
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_contention_owner
|
29
|
+
thr = Thread.current
|
30
|
+
mtx = ThreadTools::DebugMutex.new
|
31
|
+
mtx.synchronize do
|
32
|
+
Thread.new do
|
33
|
+
# previous thread still the owner
|
34
|
+
assert_equal(mtx.owner, thr)
|
35
|
+
mtx.lock
|
36
|
+
# current thread is the new owner
|
37
|
+
assert_equal(mtx.owner, Thread.current)
|
38
|
+
mtx.unlock
|
39
|
+
end
|
40
|
+
sleep 0.05
|
41
|
+
end
|
42
|
+
# we should have 1 contention
|
43
|
+
assert_equal(mtx.contentions, 1)
|
44
|
+
# owner is nil
|
45
|
+
assert_nil(mtx.owner)
|
46
|
+
end
|
47
|
+
end
|
data/thread_tools.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{thread_tools}
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.24'
|
4
4
|
s.summary = %q{Utilities for threaded apps}
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.email = %q{daniel@tralamazza.com}
|
@@ -19,11 +19,13 @@ Gem::Specification.new do |s|
|
|
19
19
|
'test/test_mongrel.rb',
|
20
20
|
'test/test_semaphore.rb',
|
21
21
|
'test/test_threadpool.rb',
|
22
|
+
'test/test_debugmutex.rb',
|
22
23
|
]
|
23
24
|
s.test_files = [
|
24
25
|
'test/test_mongrel.rb',
|
25
26
|
'test/test_semaphore.rb',
|
26
27
|
'test/test_threadpool.rb',
|
28
|
+
'test/test_debugmutex.rb',
|
27
29
|
]
|
28
30
|
s.rdoc_options = ['--main', 'README.rdoc']
|
29
31
|
s.extra_rdoc_files = ['README.rdoc']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thread_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.24"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Tralamazza
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- test/test_mongrel.rb
|
33
33
|
- test/test_semaphore.rb
|
34
34
|
- test/test_threadpool.rb
|
35
|
+
- test/test_debugmutex.rb
|
35
36
|
has_rdoc: true
|
36
37
|
homepage: http://github.com/differential/thread_tools
|
37
38
|
licenses: []
|
@@ -65,3 +66,4 @@ test_files:
|
|
65
66
|
- test/test_mongrel.rb
|
66
67
|
- test/test_semaphore.rb
|
67
68
|
- test/test_threadpool.rb
|
69
|
+
- test/test_debugmutex.rb
|