summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-28 10:45:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-28 10:45:48 +0000
commit7a622b18d9b638e8304501fa5c6fb7f60ac4ccee (patch)
treed14cb55eab89484556632f0964d81ab225136f0d
parent9646e588cb3edadab52bd8d82165949f793880a6 (diff)
test_file_exhaustive.rb: blocking flock
* test/ruby/test_file_exhaustive.rb (test_flock): add assertions for the blocking cases. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_file_exhaustive.rb58
1 files changed, 51 insertions, 7 deletions
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 5827ebb520..27a4760b98 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -662,7 +662,8 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_readlink_long_path
return unless symlinkfile
bug9157 = '[ruby-core:58592] [Bug #9157]'
- assert_separately(["-", symlinkfile, bug9157], <<-"end;")
+ assert_separately(["-", symlinkfile, bug9157], "#{<<~begin}#{<<~"end;"}")
+ begin
symlinkfile, bug9157 = *ARGV
100.step(1000, 100) do |n|
File.unlink(symlinkfile)
@@ -1250,12 +1251,55 @@ class TestFileExhaustive < Test::Unit::TestCase
rescue NotImplementedError
end
- def test_flock ## xxx
- f = File.new(regular_file, "r+")
- f.flock(File::LOCK_EX)
- f.flock(File::LOCK_SH)
- f.flock(File::LOCK_UN)
- f.close
+ def test_flock_exclusive
+ File.open(regular_file, "r+") do |f|
+ f.flock(File::LOCK_EX)
+ assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
+ begin
+ open(ARGV[0], "r") do |f|
+ Timeout.timeout(0.1) do
+ assert(!f.flock(File::LOCK_SH|File::LOCK_NB))
+ end
+ end
+ end;
+ assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
+ begin
+ open(ARGV[0], "r") do |f|
+ assert_raise(Timeout::Error) do
+ Timeout.timeout(0.1) do
+ f.flock(File::LOCK_SH)
+ end
+ end
+ end
+ end;
+ f.flock(File::LOCK_UN)
+ end
+ rescue NotImplementedError
+ end
+
+ def test_flock_shared
+ File.open(regular_file, "r+") do |f|
+ f.flock(File::LOCK_SH)
+ assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
+ begin
+ open(ARGV[0], "r") do |f|
+ Timeout.timeout(0.1) do
+ assert(f.flock(File::LOCK_SH))
+ end
+ end
+ end;
+ assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
+ begin
+ open(ARGV[0], "r") do |f|
+ assert_raise(Timeout::Error) do
+ Timeout.timeout(0.1) do
+ f.flock(File::LOCK_EX)
+ end
+ end
+ end
+ end;
+ f.flock(File::LOCK_UN)
+ end
rescue NotImplementedError
end