aboutsummaryrefslogtreecommitdiff
path: root/spec/util
diff options
context:
space:
mode:
Diffstat (limited to 'spec/util')
-rw-r--r--spec/util/test_env.lua38
1 files changed, 25 insertions, 13 deletions
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!")
837end 837end
838 838
839local 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
845end
846
839function test_env.mock_server_init() 847function 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)
853end 869end
854 870
855function test_env.mock_server_done() 871function 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
861end 873end
862 874
863local function find_binary_rock(src_rock, dir) 875local function find_binary_rock(src_rock, dir)