From 8c3b4c088236161f76955e86e8ce96f24671c973 Mon Sep 17 00:00:00 2001
From: Alexander Turenko <alexander.turenko@tarantool.org>
Date: Tue, 27 Jun 2023 00:27:50 +0300
Subject: [PATCH] test: adjust treegen for TMPDIR ending with slash

Our macOS runners have such a TMPDIR value. It breaks
`config-luatest/basic_test.lua`, because net.box seems unable to connect
a Unix domain socket using an URI with a double slash in the middle.

See the comment in the code for details.

NO_DOC=testing helper change
NO_CHANGELOG=see NO_DOC
NO_TEST=see NO_DOC
---
 test/treegen.lua | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/treegen.lua b/test/treegen.lua
index f0e8f8f456..987ff20df4 100644
--- a/test/treegen.lua
+++ b/test/treegen.lua
@@ -125,6 +125,39 @@ function treegen.prepare_directory(g, scripts, replacements)
     assert(type(replacements) == 'table')
 
     local dir = fio.tempdir()
+
+    -- fio.tempdir() follows the TMPDIR environment variable.
+    -- If it ends with a slash, the return value contains a double
+    -- slash in the middle: for example, if TMPDIR=/tmp/, the
+    -- result is like `/tmp//rfbWOJ`.
+    --
+    -- It looks harmless on the first glance, but this directory
+    -- path may be used later to form an URI for a Unix domain
+    -- socket. As result the URI looks like
+    -- `unix/:/tmp//rfbWOJ/instance-001.iproto`.
+    --
+    -- It confuses net_box.connect(): it reports EAI_NONAME error
+    -- from getaddrinfo().
+    --
+    -- It seems, the reason is a peculiar of the URI parsing:
+    --
+    -- tarantool> uri.parse('unix/:/foo/bar.iproto')
+    -- ---
+    -- - host: unix/
+    --   service: /foo/bar.iproto
+    --   unix: /foo/bar.iproto
+    -- ...
+    --
+    -- tarantool> uri.parse('unix/:/foo//bar.iproto')
+    -- ---
+    -- - host: unix
+    --   path: /foo//bar.iproto
+    -- ...
+    --
+    -- Let's normalize the path using fio.abspath(), which
+    -- eliminates the double slashes.
+    dir = fio.abspath(dir)
+
     table.insert(g.tempdirs, dir)
 
     for _, script in ipairs(scripts) do
-- 
GitLab