From 607a3ec8dc6e80732bc3329b52a496b67a857316 Mon Sep 17 00:00:00 2001 From: Tim Caswell Date: Wed, 1 Oct 2014 14:24:17 -0500 Subject: [PATCH] Fix async test --- lib/tap.lua | 8 +++++++- src/async.c | 2 +- ...-check-idle.lua => test-prepare-check-idle-async.lua} | 9 +++++++++ tests/test-timer.lua | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) rename tests/{test-prepare-check-idle.lua => test-prepare-check-idle-async.lua} (85%) diff --git a/lib/tap.lua b/lib/tap.lua index 3a74f693..d8ca0045 100644 --- a/lib/tap.lua +++ b/lib/tap.lua @@ -2,7 +2,13 @@ local uv = require('luv') local dump = require('lib/utils').dump local function protect(...) - local text = table.concat({...}, "\t") + local n = select('#', ...) + local arguments = {...} + for i = 1, n do + arguments[i] = tostring(arguments[i]) + end + + local text = table.concat(arguments, "\t") text = " " .. string.gsub(text, "\n", "\n ") print(text) end diff --git a/src/async.c b/src/async.c index d1af7355..4bf81890 100644 --- a/src/async.c +++ b/src/async.c @@ -38,8 +38,8 @@ static int luv_new_async(lua_State* L) { lua_pop(L, 1); return luv_error(L, ret); } - luv_check_callback(L, handle->data, LUV_ASYNC, 1); handle->data = luv_setup_handle(L); + luv_check_callback(L, handle->data, LUV_ASYNC, 1); return 1; } diff --git a/tests/test-prepare-check-idle.lua b/tests/test-prepare-check-idle-async.lua similarity index 85% rename from tests/test-prepare-check-idle.lua rename to tests/test-prepare-check-idle-async.lua index 94473615..9a259472 100644 --- a/tests/test-prepare-check-idle.lua +++ b/tests/test-prepare-check-idle-async.lua @@ -44,4 +44,13 @@ require('lib/tap')(function (test) end)) end) + test("simple async", function (print, p, expect, uv) + local async + async = uv.new_async(expect(function (self) + assert(self == async) + uv.close(async) + end)) + uv.async_send(async) + end) + end) diff --git a/tests/test-timer.lua b/tests/test-timer.lua index 566dc816..12982a50 100644 --- a/tests/test-timer.lua +++ b/tests/test-timer.lua @@ -63,13 +63,13 @@ require('lib/tap')(function (test) if r == 0 then uv.timer_set_repeat(timer, 8) uv.timer_again(timer) - elseif r == 1 then + elseif r == 2 then uv.timer_stop(timer) uv.close(timer) else uv.timer_set_repeat(timer, r / 2) end - end, 5), 10, 0) + end, 4), 10, 0) end) end)