Skip to content

Commit e6aaebc

Browse files
committed
test-metrics: Don't rely on hrtime busy loop
I've observed this test getting stuck in the 32-bit Windows CI, presumably because the value happens to be just about at the limit of i32 which is the integer type of LuaJIT when targeting x86-windows (ptrdiff_t). This updated test is basically a port of the libuv test `metrics_idle_time_zero` in `test-metrics.c`. A side benefit is that there's no arbitrary 1 second wait anymore.
1 parent cc1960c commit e6aaebc

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

tests/test-metrics.lua

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11

22
return require('lib/tap')(function (test)
33

4-
test("idle time", function (print, p, expect, uv)
5-
local NS_TO_MS = 1000000
6-
local timeout = 1000
7-
local timer = uv.new_timer()
8-
local counter = 0
9-
timer:start(timeout, 0, function()
10-
counter = counter + 1
11-
local t = uv.hrtime()
4+
test("metrics_info", function (print, p, expect, uv)
5+
local metrics = assert(uv.metrics_info())
6+
p(metrics)
7+
assert(metrics.loop_count >= 0)
8+
assert(metrics.events >= 0)
9+
assert(metrics.events_waiting >= 0)
10+
local init_count = metrics.loop_count
1211

13-
-- Spin for 500 ms to spin loop time out of the delta check.
14-
while uv.hrtime() - t < 600 * NS_TO_MS do end
12+
local timer = uv.new_timer()
13+
timer:start(0, 0, expect(function()
1514
timer:close()
15+
end))
1616

17-
local metrics = uv.metrics_info()
18-
p(metrics)
19-
assert(metrics.loop_count > 0)
20-
assert(metrics.events >= 0)
21-
assert(metrics.events_waiting >= 0)
22-
end)
17+
uv.run()
2318

24-
local metrics = assert(uv.metrics_info())
19+
metrics = assert(uv.metrics_info())
2520
p(metrics)
26-
assert(metrics.loop_count >= 0)
21+
assert(metrics.loop_count > init_count)
2722
assert(metrics.events >= 0)
2823
assert(metrics.events_waiting >= 0)
2924
end, "1.45.0")

0 commit comments

Comments
 (0)