[PATCH] test: fix unix socket conflict in socket.test.lua
Alexander Turenko
alexander.turenko at tarantool.org
Thu Oct 25 05:21:45 MSK 2018
It is needed to run the test in parallel on several test-run workers to
investigate flaky failures of the test.
---
issue: no
https://github.com/tarantool/tarantool/tree/Totktonada/socket-test-lua-reenterability
test/app/socket.result | 48 +++++++++++++++++++++++++++++++---------
test/app/socket.skipcond | 3 ++-
test/app/socket.test.lua | 31 +++++++++++++++++++-------
3 files changed, 63 insertions(+), 19 deletions(-)
diff --git a/test/app/socket.result b/test/app/socket.result
index 2f002a37e..1a570b9fa 100644
--- a/test/app/socket.result
+++ b/test/app/socket.result
@@ -42,6 +42,29 @@ test_run:cmd("push filter '(error: .builtin/.*[.]lua):[0-9]+' to '\\1'")
---
- true
...
+test_run:cmd("push filter '(/tmp/tarantool-test-socket)-[0-9]+' to '\\1'")
+---
+- true
+...
+-- /tmp/tarantool-test-socket-${TEST_RUN_WORKER_ID}
+test_run:cmd("setopt delimiter ';'")
+---
+- true
+...
+function get_temp_socket_path()
+ local base_path = '/tmp/tarantool-test-socket'
+ local worker_id = os.getenv('TEST_RUN_WORKER_ID')
+ if not worker_id then
+ return base_path
+ end
+ return ('%s-%s'):format(base_path, worker_id)
+end;
+---
+...
+test_run:cmd("setopt delimiter ''");
+---
+- true
+...
socket('PF_INET', 'SOCK_STREAM', 'tcp121222');
---
- null
@@ -609,13 +632,16 @@ s:nonblock()
---
- true
...
-os.remove('/tmp/tarantool-test-socket')
+path = get_temp_socket_path()
+---
+...
+os.remove(path)
---
- null
- '/tmp/tarantool-test-socket: No such file or directory'
- 2
...
-s:bind('unix/', '/tmp/tarantool-test-socket')
+s:bind('unix/', path)
---
- true
...
@@ -634,7 +660,7 @@ sc:nonblock(true)
---
- true
...
-sc:sysconnect('unix/', '/tmp/tarantool-test-socket')
+sc:sysconnect('unix/', path)
---
- true
...
@@ -673,7 +699,7 @@ s:close()
---
- true
...
-_ = os.remove('/tmp/tarantool-test-socket')
+_ = os.remove(path)
---
...
test_run:cmd("setopt delimiter ';'")
@@ -963,7 +989,7 @@ socket.tcp_connect('127.0.0.1', port), errno() == errno.ECONNREFUSED
- true
...
-- AF_UNIX
-path = '/tmp/tarantool-test-socket'
+path = get_temp_socket_path()
---
...
_ = os.remove(path)
@@ -1161,7 +1187,7 @@ master:close()
f = nil
---
...
-path = '/tmp/tarantool-test-socket'
+path = get_temp_socket_path()
---
...
s = socket('PF_UNIX', 'SOCK_STREAM', 0)
@@ -1599,7 +1625,7 @@ s = nil
---
...
-- start AF_UNIX server with dead socket exists
-path = '/tmp/tarantool-test-socket'
+path = get_temp_socket_path()
---
...
s = socket('AF_UNIX', 'SOCK_STREAM', 0)
@@ -1691,9 +1717,7 @@ test_run:cmd("setopt delimiter ';'")
err = nil;
---
...
-path = '/tmp/tarantool-test-socket';
----
-...
+path = get_temp_socket_path()
for i = 1, 10 do
local server = socket.tcp_server('unix/', path, function() end)
if not server then
@@ -2806,6 +2830,10 @@ addr = server:name()
client = socket.tcp_connect(addr.host, addr.port)
---
...
+test_run:cmd("setopt delimiter ''");
+---
+- true
+...
echo_fiber ~= nil
---
- true
diff --git a/test/app/socket.skipcond b/test/app/socket.skipcond
index 80f2117b5..c7d03a681 100644
--- a/test/app/socket.skipcond
+++ b/test/app/socket.skipcond
@@ -5,7 +5,8 @@ import os.path
import socket
import os
-test_path = '/tmp/tarantool-test-socket'
+worker_id = os.environ['TEST_RUN_WORKER_ID']
+test_path = '/tmp/tarantool-test-socket-' + worker_id
if os.path.exists(test_path):
os.remove(test_path)
diff --git a/test/app/socket.test.lua b/test/app/socket.test.lua
index c0b001449..752fdc093 100644
--- a/test/app/socket.test.lua
+++ b/test/app/socket.test.lua
@@ -12,6 +12,19 @@ type(socket)
env = require('test_run')
test_run = env.new()
test_run:cmd("push filter '(error: .builtin/.*[.]lua):[0-9]+' to '\\1'")
+test_run:cmd("push filter '(/tmp/tarantool-test-socket)-[0-9]+' to '\\1'")
+
+-- /tmp/tarantool-test-socket-${TEST_RUN_WORKER_ID}
+test_run:cmd("setopt delimiter ';'")
+function get_temp_socket_path()
+ local base_path = '/tmp/tarantool-test-socket'
+ local worker_id = os.getenv('TEST_RUN_WORKER_ID')
+ if not worker_id then
+ return base_path
+ end
+ return ('%s-%s'):format(base_path, worker_id)
+end;
+test_run:cmd("setopt delimiter ''");
socket('PF_INET', 'SOCK_STREAM', 'tcp121222');
@@ -185,14 +198,15 @@ s ~= nil
s:nonblock()
s:nonblock(true)
s:nonblock()
-os.remove('/tmp/tarantool-test-socket')
-s:bind('unix/', '/tmp/tarantool-test-socket')
+path = get_temp_socket_path()
+os.remove(path)
+s:bind('unix/', path)
sc ~= nil
s:listen(1234)
sc = socket('PF_UNIX', 'SOCK_STREAM', 0)
sc:nonblock(true)
-sc:sysconnect('unix/', '/tmp/tarantool-test-socket')
+sc:sysconnect('unix/', path)
sc:error()
s:readable()
@@ -205,7 +219,7 @@ sc:close()
sa:close()
s:close()
-_ = os.remove('/tmp/tarantool-test-socket')
+_ = os.remove(path)
test_run:cmd("setopt delimiter ';'")
function aexitst(ai, hostnames, port)
@@ -306,7 +320,7 @@ s:close()
socket.tcp_connect('127.0.0.1', port), errno() == errno.ECONNREFUSED
-- AF_UNIX
-path = '/tmp/tarantool-test-socket'
+path = get_temp_socket_path()
_ = os.remove(path)
s = socket('AF_UNIX', 'SOCK_STREAM', 0)
s:bind('unix/', path)
@@ -383,7 +397,7 @@ master:close()
f = nil
-path = '/tmp/tarantool-test-socket'
+path = get_temp_socket_path()
s = socket('PF_UNIX', 'SOCK_STREAM', 0)
s:setsockopt('SOL_SOCKET', 'SO_REUSEADDR', true)
s:error()
@@ -531,7 +545,7 @@ yaml.decode(yaml.encode(s)).fd == s:fd()
s = nil
-- start AF_UNIX server with dead socket exists
-path = '/tmp/tarantool-test-socket'
+path = get_temp_socket_path()
s = socket('AF_UNIX', 'SOCK_STREAM', 0)
s:bind('unix/', path)
s:close()
@@ -569,7 +583,7 @@ f:cancel()
-- and used by a newly started one.
test_run:cmd("setopt delimiter ';'")
err = nil;
-path = '/tmp/tarantool-test-socket';
+path = get_temp_socket_path()
for i = 1, 10 do
local server = socket.tcp_server('unix/', path, function() end)
if not server then
@@ -954,6 +968,7 @@ end, name = 'echoserv'});
test_run:cmd("setopt delimiter ''");
addr = server:name()
client = socket.tcp_connect(addr.host, addr.port)
+test_run:cmd("setopt delimiter ''");
echo_fiber ~= nil
client:write('hello')
client:read(5, 0.1) == 'hello'
--
2.19.1
More information about the Tarantool-patches
mailing list