mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
9646e588cb
commit
7a622b18d9
1 changed files with 51 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue