spec/util_poll_spec.lua
author Kim Alvefur <zash@zash.se>
Sat, 02 Mar 2024 13:23:24 +0100
changeset 13456 69faf3552d52
parent 12404 728d1c1dc7db
permissions -rw-r--r--
mod_posix: Move POSIX signal handling into util.startup to avoid race When libunbound is initialized, it spawns a thread to work in. In case a module initializes libunbound, e.g. by triggering a s2s connection, Prosody would not handle signals, instead immediately quit on e.g. the reload (SIGHUP) signal. Likely because the libunbound thread would not have inherited the signal mask from the main Prosody thread. Thanks Menel, riau and franck-x for reporting and help narrowing down

describe("util.poll", function()
	local poll;
	setup(function()
		poll = require "util.poll";
	end);
	it("loads", function()
		assert.is_table(poll);
		assert.is_function(poll.new);
		assert.is_string(poll.api);
	end);
	describe("new", function()
		local p;
		setup(function()
			p = poll.new();
		end)
		it("times out", function ()
			local fd, err = p:wait(0);
			assert.falsy(fd);
			assert.equal("timeout", err);
		end);
		it("works", function()
			-- stdout should be writable, right?
			assert.truthy(p:add(1, false, true));
			local fd, r, w = p:wait(1);
			assert.is_number(fd);
			assert.is_boolean(r);
			assert.is_boolean(w);
			assert.equal(1, fd);
			assert.falsy(r);
			assert.truthy(w);
			assert.truthy(p:del(1));
		end);
	end)
end);