Skip to content

Commit 3da4aa5

Browse files
committed
Fix flaky tests
1 parent 27a7b41 commit 3da4aa5

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
.luarocks
33
.rocks
44

5-
/tmp
5+
/tmp/*
66
!/tmp/.keep

test/process_test.lua

+14-9
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ end
1717

1818
g.test_start = function()
1919
process = Process:start('/bin/sleep', {'5'})
20-
fiber.sleep(0.1)
21-
t.assertEquals(os.execute('ps -p ' .. process.pid .. ' > /dev/null'), 0)
20+
t.helpers.retrying({timeout = 0.5}, function()
21+
t.assertEquals(os.execute('ps -p ' .. process.pid .. ' > /dev/null'), 0)
22+
end)
2223
process:kill()
23-
fiber.sleep(0.1)
24-
t.assertNotEquals(os.execute('ps -p ' .. process.pid .. ' > /dev/null'), 0)
24+
t.helpers.retrying({timeout = 0.5}, function()
25+
t.assertNotEquals(os.execute('ps -p ' .. process.pid .. ' > /dev/null'), 0)
26+
end)
2527
kill_after_test = false
2628
end
2729

@@ -41,11 +43,14 @@ g.test_chdir = function()
4143
end
4244
os.execute('touch ./tmp/' .. file)
4345

44-
Process:start('/bin/cp', {file, file_copy})
45-
fiber.sleep(0.1)
46-
t.assertEquals(fio.stat('./tmp/' .. file_copy), nil)
46+
local proc = Process:start('/bin/cp', {file, file_copy})
47+
t.helpers.retrying({timeout = 0.5}, function()
48+
t.assertNotEquals(os.execute('ps -p ' .. proc.pid .. ' > /dev/null'), 0)
49+
t.assertEquals(fio.stat('./tmp/' .. file_copy), nil)
50+
end)
4751

4852
Process:start('/bin/cp', {file, file_copy}, {}, {chdir = './tmp'})
49-
fiber.sleep(0.1)
50-
t.assertNotEquals(fio.stat('./tmp/' .. file_copy), nil)
53+
t.helpers.retrying({timeout = 0.5}, function()
54+
t.assertNotEquals(fio.stat('./tmp/' .. file_copy), nil)
55+
end)
5156
end

test/server_test.lua

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local fiber = require('fiber')
21
local fio = require('fio')
32
local json = require('json')
43

@@ -39,10 +38,14 @@ g.test_start_stop = function()
3938
fio.mktree(workdir)
4039
local s = Server:new({command = command, workdir = workdir})
4140
s:start()
42-
fiber.sleep(0.1)
43-
t.assertEquals(os.execute('ps -p ' .. s.process.pid .. ' > /dev/null'), 0)
41+
local pid = s.process.pid
42+
t.helpers.retrying({timeout = 0.5}, function()
43+
t.assertEquals(os.execute('ps -p ' .. pid .. ' > /dev/null'), 0)
44+
end)
4445
s:stop()
45-
fiber.sleep(0.1)
46+
t.helpers.retrying({timeout = 0.5}, function()
47+
t.assertEquals(os.execute('ps -p ' .. pid .. ' > /dev/null'), 256) -- luajit multiplies code by 256
48+
end)
4649
end
4750

4851
g.test_http_request = function()

tmp/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)