about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorHleb Valoshka <375gnu@gmail.com>2013-09-07 23:07:36 +0300
committerEric Wong <normalperson@yhbt.net>2013-09-07 20:18:49 +0000
commitc3be428c452fd9c91d31b5b7d5b697175b6652df (patch)
treeec9915870584f14392a613462ba408c024189f39
parentff940137dc5098c9d8094e041e9be053cb3e139f (diff)
downloadkgio-c3be428c452fd9c91d31b5b7d5b697175b6652df.tar.gz
When a Tempfile object is garbage collected, or when the Ruby interpreter
exits, its associated temporary file is automatically deleted. This may
lead to race condition when Tempfile is used like in these tests.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
-rw-r--r--test/test_autopush.rb3
-rw-r--r--test/test_unix_client_read_server_write.rb3
-rw-r--r--test/test_unix_connect.rb3
-rw-r--r--test/test_unix_server.rb3
-rw-r--r--test/test_unix_server_read_client_write.rb3
5 files changed, 5 insertions, 10 deletions
diff --git a/test/test_autopush.rb b/test/test_autopush.rb
index 6c6e05f..38b7c52 100644
--- a/test/test_autopush.rb
+++ b/test/test_autopush.rb
@@ -44,8 +44,7 @@ class TestAutopush < Test::Unit::TestCase
     Kgio.autopush = true
     tmp = Tempfile.new('kgio_unix')
     @path = tmp.path
-    File.unlink(@path)
-    tmp.close rescue nil
+    tmp.close!
     @srv = Kgio::UNIXServer.new(@path)
     @rd = Kgio::UNIXSocket.new(@path)
     t0 = nil
diff --git a/test/test_unix_client_read_server_write.rb b/test/test_unix_client_read_server_write.rb
index 2f2b7b9..c8835cd 100644
--- a/test/test_unix_client_read_server_write.rb
+++ b/test/test_unix_client_read_server_write.rb
@@ -7,8 +7,7 @@ class TestUnixClientReadServerWrite < Test::Unit::TestCase
     @tmpdir = Dir.mktmpdir('kgio_unix_0')
     tmp = Tempfile.new('kgio_unix_0', @tmpdir)
     @path = tmp.path
-    File.unlink(@path)
-    tmp.close rescue nil
+    tmp.close!
     @srv = Kgio::UNIXServer.new(@path)
     @rd = Kgio::UNIXSocket.new(@path)
     @wr = @srv.kgio_tryaccept
diff --git a/test/test_unix_connect.rb b/test/test_unix_connect.rb
index 60cb8c0..7b19941 100644
--- a/test/test_unix_connect.rb
+++ b/test/test_unix_connect.rb
@@ -18,8 +18,7 @@ class TestKgioUnixConnect < Test::Unit::TestCase
     @tmpdir = Dir.mktmpdir('kgio_unix_1')
     tmp = Tempfile.new('kgio_unix_1', @tmpdir)
     @path = tmp.path
-    File.unlink(@path)
-    tmp.close rescue nil
+    tmp.close!
     @srv = Kgio::UNIXServer.new(@path)
     @addr = Socket.pack_sockaddr_un(@path)
   end
diff --git a/test/test_unix_server.rb b/test/test_unix_server.rb
index 02e4d8d..96769b1 100644
--- a/test/test_unix_server.rb
+++ b/test/test_unix_server.rb
@@ -8,8 +8,7 @@ class TestKgioUNIXServer < Test::Unit::TestCase
     @tmpdir = Dir.mktmpdir('kgio_unix_2')
     tmp = Tempfile.new('kgio_unix_2', @tmpdir)
     @path = tmp.path
-    File.unlink(@path)
-    tmp.close rescue nil
+    tmp.close!
     @srv = Kgio::UNIXServer.new(@path)
     @host = '127.0.0.1'
   end
diff --git a/test/test_unix_server_read_client_write.rb b/test/test_unix_server_read_client_write.rb
index a994e01..24581e1 100644
--- a/test/test_unix_server_read_client_write.rb
+++ b/test/test_unix_server_read_client_write.rb
@@ -7,8 +7,7 @@ class TestUnixServerReadClientWrite < Test::Unit::TestCase
     @tmpdir = Dir.mktmpdir('kgio_unix_3')
     tmp = Tempfile.new('kgio_unix_3', @tmpdir)
     @path = tmp.path
-    File.unlink(@path)
-    tmp.close rescue nil
+    tmp.close!
     @srv = Kgio::UNIXServer.new(@path)
     @wr = Kgio::UNIXSocket.new(@path)
     @rd = @srv.kgio_tryaccept