spec/count_down_latch.rb in fssm-0.2.5 vs spec/count_down_latch.rb in fssm-0.2.6
- old
+ new
@@ -7,11 +7,11 @@
attr_reader :count
def initialize(to)
@count = to.to_i
raise ArgumentError, "cannot count down from negative integer" unless @count >= 0
- @lock = Mutex.new
+ @lock = Mutex.new
@condition = ConditionVariable.new
end
def count_down
@lock.synchronize do
@@ -35,11 +35,11 @@
assert_raise(ArgumentError) { CountDownLatch.new(-1) }
end
def test_basic_latch_usage
latch = CountDownLatch.new(1)
- name = "foo"
+ name = "foo"
Thread.new do
name = "bar"
latch.count_down
end
latch.wait
@@ -47,11 +47,11 @@
assert_equal("bar", name)
end
def test_basic_latch_usage_inverted
latch = CountDownLatch.new(1)
- name = "foo"
+ name = "foo"
Thread.new do
latch.wait
assert_equal(0, latch.count)
assert_equal("bar", name)
end
@@ -65,11 +65,11 @@
assert_equal(0, latch.count)
end
def test_count_down_twice_with_thread
latch = CountDownLatch.new(2)
- name = "foo"
+ name = "foo"
Thread.new do
latch.count_down
name = "bar"
latch.count_down
end
@@ -78,11 +78,11 @@
assert_equal("bar", name)
end
def test_count_down_twice_with_two_parallel_threads
latch = CountDownLatch.new(2)
- name = "foo"
+ name = "foo"
Thread.new { latch.count_down }
Thread.new do
name = "bar"
latch.count_down
end
@@ -91,11 +91,11 @@
assert_equal("bar", name)
end
def test_count_down_twice_with_two_chained_threads
latch = CountDownLatch.new(2)
- name = "foo"
+ name = "foo"
Thread.new do
latch.count_down
Thread.new do
name = "bar"
latch.count_down
@@ -106,12 +106,12 @@
assert_equal("bar", name)
end
def test_count_down_with_multiple_waiters
proceed_latch = CountDownLatch.new(2)
- check_latch = CountDownLatch.new(2)
- results = {}
+ check_latch = CountDownLatch.new(2)
+ results = {}
Thread.new do
proceed_latch.wait
results[:first] = 1
check_latch.count_down
end
@@ -129,12 +129,12 @@
assert_equal({:first => 1, :second => 2}, results)
end
def test_interleaved_latches
change_1_latch = CountDownLatch.new(1)
- check_latch = CountDownLatch.new(1)
+ check_latch = CountDownLatch.new(1)
change_2_latch = CountDownLatch.new(1)
- name = "foo"
+ name = "foo"
Thread.new do
name = "bar"
change_1_latch.count_down
check_latch.wait
name = "man"