diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2022-02-16 22:15:28 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2022-02-17 12:47:25 -0300 |
commit | 6c524b4a1b9fec2fe4abf03fa83b8d6624c23e26 (patch) | |
tree | e288246223281604d5dfdc8471e05f9389c2984a /spec | |
parent | d1d4694d3f216030cc9653d95963a30f287f2247 (diff) | |
download | luarocks-6c524b4a1b9fec2fe4abf03fa83b8d6624c23e26.tar.gz luarocks-6c524b4a1b9fec2fe4abf03fa83b8d6624c23e26.tar.bz2 luarocks-6c524b4a1b9fec2fe4abf03fa83b8d6624c23e26.zip |
tests: wait longer for mock server to start
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fetch_spec.lua | 5 | ||||
-rw-r--r-- | spec/util/test_env.lua | 38 |
2 files changed, 29 insertions, 14 deletions
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 008a91c8..0087159b 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
@@ -39,7 +39,8 @@ describe("luarocks fetch #unit #mock", function() | |||
39 | describe("fetch.fetch_url", function() | 39 | describe("fetch.fetch_url", function() |
40 | 40 | ||
41 | it("fetches the url argument and returns the absolute path of the fetched file", function() | 41 | it("fetches the url argument and returns the absolute path of the fetched file", function() |
42 | local fetchedfile = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") | 42 | local fetchedfile, err = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") |
43 | assert(fetchedfile, err) | ||
43 | assert.truthy(are_same_files(fetchedfile, lfs.currentdir() .. "/a_rock.lua")) | 44 | assert.truthy(are_same_files(fetchedfile, lfs.currentdir() .. "/a_rock.lua")) |
44 | local fd = assert(io.open(fetchedfile, "r")) | 45 | local fd = assert(io.open(fetchedfile, "r")) |
45 | local fetchedcontent = assert(fd:read("*a")) | 46 | local fetchedcontent = assert(fd:read("*a")) |
@@ -109,6 +110,7 @@ describe("luarocks fetch #unit #mock", function() | |||
109 | 110 | ||
110 | it("returns true and fetches the url into a temporary dir", function() | 111 | it("returns true and fetches the url into a temporary dir", function() |
111 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test") | 112 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test") |
113 | assert(fetchedfile, tmpdir) | ||
112 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/a_rock.lua")) | 114 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/a_rock.lua")) |
113 | local fd = assert(io.open(fetchedfile, "r")) | 115 | local fd = assert(io.open(fetchedfile, "r")) |
114 | local fetchedcontent = assert(fd:read("*a")) | 116 | local fetchedcontent = assert(fd:read("*a")) |
@@ -121,6 +123,7 @@ describe("luarocks fetch #unit #mock", function() | |||
121 | 123 | ||
122 | it("returns true and fetches the url into a temporary dir with custom filename", function() | 124 | it("returns true and fetches the url into a temporary dir with custom filename", function() |
123 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test", "my_a_rock.lua") | 125 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test", "my_a_rock.lua") |
126 | assert(fetchedfile, tmpdir) | ||
124 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/my_a_rock.lua")) | 127 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/my_a_rock.lua")) |
125 | assert.truthy(string.find(tmpdir, "test")) | 128 | assert.truthy(string.find(tmpdir, "test")) |
126 | local fd = assert(io.open(fetchedfile, "r")) | 129 | local fd = assert(io.open(fetchedfile, "r")) |
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 35c27dc8..c40921cc 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -836,28 +836,40 @@ local function setup_luarocks() | |||
836 | print("LuaRocks set up correctly!") | 836 | print("LuaRocks set up correctly!") |
837 | end | 837 | end |
838 | 838 | ||
839 | local function mock_api_call(path) | ||
840 | if test_env.TEST_TARGET_OS == "windows" then | ||
841 | return test_env.execute(Q(test_env.testing_paths.win_tools .. "/wget") .. " --quiet --timeout=5 --tries=1 localhost:8080" .. path) | ||
842 | else | ||
843 | return test_env.execute("curl localhost:8080" .. path) | ||
844 | end | ||
845 | end | ||
846 | |||
839 | function test_env.mock_server_init() | 847 | function test_env.mock_server_init() |
840 | local testing_paths = test_env.testing_paths | 848 | local testing_paths = test_env.testing_paths |
841 | assert(test_env.need_rock("restserver-xavante")) | 849 | assert(test_env.need_rock("restserver-xavante")) |
842 | local final_command | 850 | |
843 | local sleep_command | ||
844 | if test_env.TEST_TARGET_OS == "windows" then | 851 | if test_env.TEST_TARGET_OS == "windows" then |
845 | final_command = test_env.execute_helper("start /b \"\" " .. Q(testing_paths.lua) .. " " .. Q(testing_paths.util_dir .. "/mock-server.lua") .. " " .. Q(testing_paths.fixtures_dir), true, test_env.env_variables) | 852 | os.execute(test_env.execute_helper("start /b \"\" " .. Q(testing_paths.lua) .. " " .. Q(testing_paths.util_dir .. "/mock-server.lua") .. " " .. Q(testing_paths.fixtures_dir), true, test_env.env_variables)) |
846 | sleep_command = "timeout 1 > NUL" | ||
847 | else | 853 | else |
848 | final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua " .. testing_paths.fixtures_dir .. " &", true, test_env.env_variables) | 854 | os.execute(test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua " .. testing_paths.fixtures_dir .. " &", true, test_env.env_variables)) |
849 | sleep_command = "sleep 1" | 855 | end |
856 | |||
857 | for _ = 1, 10 do | ||
858 | if mock_api_call("/api/tool_version") then | ||
859 | break | ||
860 | end | ||
861 | |||
862 | if test_env.TEST_TARGET_OS == "windows" then | ||
863 | os.execute("timeout 1 > NUL") | ||
864 | else | ||
865 | os.execute("sleep 1") | ||
866 | end | ||
850 | end | 867 | end |
851 | os.execute(final_command) | 868 | |
852 | os.execute(sleep_command) | ||
853 | end | 869 | end |
854 | 870 | ||
855 | function test_env.mock_server_done() | 871 | function test_env.mock_server_done() |
856 | if test_env.TEST_TARGET_OS == "windows" then | 872 | mock_api_call("/shutdown") |
857 | os.execute(Q(test_env.testing_paths.win_tools .. "/wget") .. " --quiet --timeout=5 --tries=1 localhost:8080/shutdown") | ||
858 | else | ||
859 | os.execute("curl localhost:8080/shutdown") | ||
860 | end | ||
861 | end | 873 | end |
862 | 874 | ||
863 | local function find_binary_rock(src_rock, dir) | 875 | local function find_binary_rock(src_rock, dir) |