Changeset

7505:3d950ee0de35

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 14 Jul 2016 13:41:02 +0200
parents 7497:22942eda53f8 (current diff) 7504:b43cbbbb806f (diff)
children 7506:8cca24bea3e0
files net/server_select.lua
diffstat 7 files changed, 209 insertions(+), 188 deletions(-) [+]
line wrap: on
line diff
--- a/fallbacks/bit.lua	Wed Jul 13 18:43:33 2016 +0200
+++ b/fallbacks/bit.lua	Thu Jul 14 13:41:02 2016 +0200
@@ -68,7 +68,7 @@
 end
 function rshift(a, i)
 	local t = {a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]};
-	for n = 1,i do _rshift1(t); end
+	for _ = 1, i do _rshift1(t); end
 	return setmetatable(t, bit_mt);
 end
 local function _arshift1(t)
@@ -81,7 +81,7 @@
 end
 function arshift(a, i)
 	local t = {a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]};
-	for n = 1,i do _arshift1(t); end
+	for _ = 1, i do _arshift1(t); end
 	return setmetatable(t, bit_mt);
 end
 local function _lshift1(t)
@@ -94,7 +94,7 @@
 end
 function lshift(a, i)
 	local t = {a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]};
-	for n = 1,i do _lshift1(t); end
+	for _ = 1, i do _lshift1(t); end
 	return setmetatable(t, bit_mt);
 end
 
--- a/net/dns.lua	Wed Jul 13 18:43:33 2016 +0200
+++ b/net/dns.lua	Thu Jul 14 13:41:02 2016 +0200
@@ -386,7 +386,7 @@
 
 function resolver:AAAA(rr)
 	local addr = {};
-	for i = 1, rr.rdlength, 2 do
+	for _ = 1, rr.rdlength, 2 do
 		local b1, b2 = self:byte(2);
 		table.insert(addr, ("%02x%02x"):format(b1, b2));
 	end
@@ -523,7 +523,7 @@
 
 function resolver:rrs (count)    -- - - - - - - - - - - - - - - - - - - - - rrs
 	local rrs = {};
-	for i = 1,count do append(rrs, self:rr()); end
+	for _ = 1, count do append(rrs, self:rr()); end
 	return rrs;
 end
 
@@ -536,7 +536,7 @@
 
 	response.question = {};
 	local offset = self.offset;
-	for i = 1,response.header.qdcount do
+	for _ = 1, response.header.qdcount do
 		append(response.question, self:question());
 	end
 	response.question.raw = string.sub(self.packet, offset, self.offset - 1);
@@ -1026,7 +1026,7 @@
 	local tmp;
 	for _, s in pairs({'answer', 'authority', 'additional'}) do
 		for i,rr in pairs(response[s]) do
-			for j,t in pairs({ 'name', 'type', 'class', 'ttl', 'rdlength' }) do
+			for _, t in pairs({ 'name', 'type', 'class', 'ttl', 'rdlength' }) do
 				tmp = string.format('%s[%i].%s', s, i, t);
 				print(string.format('%-30s', tmp), rr[t], hint(rr, t));
 			end
--- a/net/server_select.lua	Wed Jul 13 18:43:33 2016 +0200
+++ b/net/server_select.lua	Thu Jul 14 13:41:02 2016 +0200
@@ -562,7 +562,7 @@
 		local read, wrote
 		handshake = coroutine_wrap( function( client ) -- create handshake coroutine
 				local err
-				for i = 1, _maxsslhandshake do
+				for _ = 1, _maxsslhandshake do
 					_sendlistlen = ( wrote and removesocket( _sendlist, client, _sendlistlen ) ) or _sendlistlen
 					_readlistlen = ( read and removesocket( _readlist, client, _readlistlen ) ) or _readlistlen
 					read, wrote = nil, nil
--- a/plugins/mod_net_multiplex.lua	Wed Jul 13 18:43:33 2016 +0200
+++ b/plugins/mod_net_multiplex.lua	Thu Jul 14 13:41:02 2016 +0200
@@ -19,7 +19,7 @@
 module:hook("service-removed", function (event)	available_services[event.service] = nil; end);
 
 for service_name, services in pairs(portmanager.get_registered_services()) do
-	for i, service in ipairs(services) do
+	for _, service in ipairs(services) do
 		add_service(service);
 	end
 end
--- a/tests/run_tests.sh	Wed Jul 13 18:43:33 2016 +0200
+++ b/tests/run_tests.sh	Thu Jul 14 13:41:02 2016 +0200
@@ -1,3 +1,3 @@
 #!/bin/sh
 rm reports/*.report
-exec lua test.lua $*
+exec lua test.lua "$@"
--- a/tests/test_util_cache.lua	Wed Jul 13 18:43:33 2016 +0200
+++ b/tests/test_util_cache.lua	Thu Jul 14 13:41:02 2016 +0200
@@ -117,143 +117,154 @@
 	assert_equal(c:get("eight"), 8);
 	assert_equal(c:get("nine"), 9);
 
-	local keys = { "nine", "four", "eight", "seven", "six" };
-	local values = { 9, 4, 8, 7, 6 };
-	local i = 0;	
-	for k, v in c:items() do
-		i = i + 1;
-		assert_equal(k, keys[i]);
-		assert_equal(v, values[i]);
-	end
-	assert_equal(i, 5);
-	
-	c:set("four", "2+2");
-	assert_equal(c:count(), 5);
+	do
+		local keys = { "nine", "four", "eight", "seven", "six" };
+		local values = { 9, 4, 8, 7, 6 };
+		local i = 0;
+		for k, v in c:items() do
+			i = i + 1;
+			assert_equal(k, keys[i]);
+			assert_equal(v, values[i]);
+		end
+		assert_equal(i, 5);
 
-	assert_equal(c:get("one"), nil);
-	assert_equal(c:get("two"), nil);
-	assert_equal(c:get("three"), nil);
-	assert_equal(c:get("four"), "2+2");
-	assert_equal(c:get("five"), nil);
-	assert_equal(c:get("six"), 6);
-	assert_equal(c:get("seven"), 7);
-	assert_equal(c:get("eight"), 8);
-	assert_equal(c:get("nine"), 9);
+		c:set("four", "2+2");
+		assert_equal(c:count(), 5);
 
-	local keys = { "four", "nine", "eight", "seven", "six" };
-	local values = { "2+2", 9, 8, 7, 6 };
-	local i = 0;	
-	for k, v in c:items() do
-		i = i + 1;
-		assert_equal(k, keys[i]);
-		assert_equal(v, values[i]);
+		assert_equal(c:get("one"), nil);
+		assert_equal(c:get("two"), nil);
+		assert_equal(c:get("three"), nil);
+		assert_equal(c:get("four"), "2+2");
+		assert_equal(c:get("five"), nil);
+		assert_equal(c:get("six"), 6);
+		assert_equal(c:get("seven"), 7);
+		assert_equal(c:get("eight"), 8);
+		assert_equal(c:get("nine"), 9);
 	end
-	assert_equal(i, 5);
-	
-	c:set("foo", nil);
-	assert_equal(c:count(), 5);
 
-	assert_equal(c:get("one"), nil);
-	assert_equal(c:get("two"), nil);
-	assert_equal(c:get("three"), nil);
-	assert_equal(c:get("four"), "2+2");
-	assert_equal(c:get("five"), nil);
-	assert_equal(c:get("six"), 6);
-	assert_equal(c:get("seven"), 7);
-	assert_equal(c:get("eight"), 8);
-	assert_equal(c:get("nine"), 9);
+	do
+		local keys = { "four", "nine", "eight", "seven", "six" };
+		local values = { "2+2", 9, 8, 7, 6 };
+		local i = 0;
+		for k, v in c:items() do
+			i = i + 1;
+			assert_equal(k, keys[i]);
+			assert_equal(v, values[i]);
+		end
+		assert_equal(i, 5);
+
+		c:set("foo", nil);
+		assert_equal(c:count(), 5);
 
-	local keys = { "four", "nine", "eight", "seven", "six" };
-	local values = { "2+2", 9, 8, 7, 6 };
-	local i = 0;	
-	for k, v in c:items() do
-		i = i + 1;
-		assert_equal(k, keys[i]);
-		assert_equal(v, values[i]);
+		assert_equal(c:get("one"), nil);
+		assert_equal(c:get("two"), nil);
+		assert_equal(c:get("three"), nil);
+		assert_equal(c:get("four"), "2+2");
+		assert_equal(c:get("five"), nil);
+		assert_equal(c:get("six"), 6);
+		assert_equal(c:get("seven"), 7);
+		assert_equal(c:get("eight"), 8);
+		assert_equal(c:get("nine"), 9);
 	end
-	assert_equal(i, 5);
-	
-	c:set("four", nil);
-	
-	assert_equal(c:get("one"), nil);
-	assert_equal(c:get("two"), nil);
-	assert_equal(c:get("three"), nil);
-	assert_equal(c:get("four"), nil);
-	assert_equal(c:get("five"), nil);
-	assert_equal(c:get("six"), 6);
-	assert_equal(c:get("seven"), 7);
-	assert_equal(c:get("eight"), 8);
-	assert_equal(c:get("nine"), 9);
+
+	do
+		local keys = { "four", "nine", "eight", "seven", "six" };
+		local values = { "2+2", 9, 8, 7, 6 };
+		local i = 0;
+		for k, v in c:items() do
+			i = i + 1;
+			assert_equal(k, keys[i]);
+			assert_equal(v, values[i]);
+		end
+		assert_equal(i, 5);
+
+		c:set("four", nil);
+
+		assert_equal(c:get("one"), nil);
+		assert_equal(c:get("two"), nil);
+		assert_equal(c:get("three"), nil);
+		assert_equal(c:get("four"), nil);
+		assert_equal(c:get("five"), nil);
+		assert_equal(c:get("six"), 6);
+		assert_equal(c:get("seven"), 7);
+		assert_equal(c:get("eight"), 8);
+		assert_equal(c:get("nine"), 9);
+	end
 
-	local keys = { "nine", "eight", "seven", "six" };
-	local values = { 9, 8, 7, 6 };
-	local i = 0;	
-	for k, v in c:items() do
-		i = i + 1;
-		assert_equal(k, keys[i]);
-		assert_equal(v, values[i]);
+	do
+		local keys = { "nine", "eight", "seven", "six" };
+		local values = { 9, 8, 7, 6 };
+		local i = 0;
+		for k, v in c:items() do
+			i = i + 1;
+			assert_equal(k, keys[i]);
+			assert_equal(v, values[i]);
+		end
+		assert_equal(i, 4);
 	end
-	assert_equal(i, 4);
-	
-	local evicted_key, evicted_value;
-	local c2 = new(3, function (_key, _value)
-		evicted_key, evicted_value = _key, _value;
-	end);
-	local function set(k, v, should_evict_key, should_evict_value)
-		evicted_key, evicted_value = nil, nil;
-		c2:set(k, v);
-		assert_equal(evicted_key, should_evict_key);
-		assert_equal(evicted_value, should_evict_value);
+
+	do
+		local evicted_key, evicted_value;
+		local c2 = new(3, function (_key, _value)
+			evicted_key, evicted_value = _key, _value;
+		end);
+		local function set(k, v, should_evict_key, should_evict_value)
+			evicted_key, evicted_value = nil, nil;
+			c2:set(k, v);
+			assert_equal(evicted_key, should_evict_key);
+			assert_equal(evicted_value, should_evict_value);
+		end
+		set("a", 1)
+		set("a", 1)
+		set("a", 1)
+		set("a", 1)
+		set("a", 1)
+
+		set("b", 2)
+		set("c", 3)
+		set("b", 2)
+		set("d", 4, "a", 1)
+		set("e", 5, "c", 3)
 	end
-	set("a", 1)
-	set("a", 1)
-	set("a", 1)
-	set("a", 1)
-	set("a", 1)
-
-	set("b", 2)
-	set("c", 3)
-	set("b", 2)
-	set("d", 4, "a", 1)
-	set("e", 5, "c", 3)
-	
 
-	local evicted_key, evicted_value;
-	local c3 = new(1, function (_key, _value)
-		evicted_key, evicted_value = _key, _value;
-		if _key == "a" then
-			-- Sanity check for what we're evicting
-			assert_equal(_key, "a");
-			assert_equal(_value, 1);
-			-- We're going to block eviction of this key/value, so set to nil...
+	do
+		local evicted_key, evicted_value;
+		local c3 = new(1, function (_key, _value)
+			evicted_key, evicted_value = _key, _value;
+			if _key == "a" then
+				-- Sanity check for what we're evicting
+				assert_equal(_key, "a");
+				assert_equal(_value, 1);
+				-- We're going to block eviction of this key/value, so set to nil...
+				evicted_key, evicted_value = nil, nil;
+				-- Returning false to block eviction
+				return false
+			end
+		end);
+		local function set(k, v, should_evict_key, should_evict_value)
 			evicted_key, evicted_value = nil, nil;
-			-- Returning false to block eviction
-			return false
+			local ret = c3:set(k, v);
+			assert_equal(evicted_key, should_evict_key);
+			assert_equal(evicted_value, should_evict_value);
+			return ret;
 		end
-	end);
-	local function set(k, v, should_evict_key, should_evict_value)
-		evicted_key, evicted_value = nil, nil;
-		local ret = c3:set(k, v);
-		assert_equal(evicted_key, should_evict_key);
-		assert_equal(evicted_value, should_evict_value);
-		return ret;
+		set("a", 1)
+		set("a", 1)
+		set("a", 1)
+		set("a", 1)
+		set("a", 1)
+
+		-- Our on_evict prevents "a" from being evicted, causing this to fail...
+		assert_equal(set("b", 2), false, "Failed to prevent eviction, or signal result");
+
+		expect_kv("a", 1, c3:head());
+		expect_kv("a", 1, c3:tail());
+
+		-- Check the final state is what we expect
+		assert_equal(c3:get("a"), 1);
+		assert_equal(c3:get("b"), nil);
+		assert_equal(c3:count(), 1);
 	end
-	set("a", 1)
-	set("a", 1)
-	set("a", 1)
-	set("a", 1)
-	set("a", 1)
-
-	-- Our on_evict prevents "a" from being evicted, causing this to fail...
-	assert_equal(set("b", 2), false, "Failed to prevent eviction, or signal result");
-	
-	expect_kv("a", 1, c3:head());
-	expect_kv("a", 1, c3:tail());
-	
-	-- Check the final state is what we expect
-	assert_equal(c3:get("a"), 1);
-	assert_equal(c3:get("b"), nil);
-	assert_equal(c3:count(), 1);
 
 
 	local c4 = new(3, false);
--- a/tests/test_util_stanza.lua	Wed Jul 13 18:43:33 2016 +0200
+++ b/tests/test_util_stanza.lua	Thu Jul 14 13:41:02 2016 +0200
@@ -80,63 +80,73 @@
 end
 
 function reply(reply, _M)
-	-- Test stanza
-	local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
-		:tag("child1");
-	-- Make reply stanza
-	local r = reply(s);
-	assert_equal(r.name, s.name);
-	assert_equal(r.id, s.id);
-	assert_equal(r.attr.to, s.attr.from);
-	assert_equal(r.attr.from, s.attr.to);
-	assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
+	do
+		-- Test stanza
+		local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
+			:tag("child1");
+		-- Make reply stanza
+		local r = reply(s);
+		assert_equal(r.name, s.name);
+		assert_equal(r.id, s.id);
+		assert_equal(r.attr.to, s.attr.from);
+		assert_equal(r.attr.from, s.attr.to);
+		assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
+	end
 
-	-- Test stanza
-	local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
-		:tag("child1");
-	-- Make reply stanza
-	local r = reply(s);
-	assert_equal(r.name, s.name);
-	assert_equal(r.id, s.id);
-	assert_equal(r.attr.to, s.attr.from);
-	assert_equal(r.attr.from, s.attr.to);
-	assert_equal(r.attr.type, "result");
-	assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
+	do
+		-- Test stanza
+		local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
+			:tag("child1");
+		-- Make reply stanza
+		local r = reply(s);
+		assert_equal(r.name, s.name);
+		assert_equal(r.id, s.id);
+		assert_equal(r.attr.to, s.attr.from);
+		assert_equal(r.attr.from, s.attr.to);
+		assert_equal(r.attr.type, "result");
+		assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
+	end
 
-	-- Test stanza
-	local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "set" })
-		:tag("child1");
-	-- Make reply stanza
-	local r = reply(s);
-	assert_equal(r.name, s.name);
-	assert_equal(r.id, s.id);
-	assert_equal(r.attr.to, s.attr.from);
-	assert_equal(r.attr.from, s.attr.to);
-	assert_equal(r.attr.type, "result");
-	assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
+	do
+		-- Test stanza
+		local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "set" })
+			:tag("child1");
+		-- Make reply stanza
+		local r = reply(s);
+		assert_equal(r.name, s.name);
+		assert_equal(r.id, s.id);
+		assert_equal(r.attr.to, s.attr.from);
+		assert_equal(r.attr.from, s.attr.to);
+		assert_equal(r.attr.type, "result");
+		assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
+	end
 end
 
 function error_reply(error_reply, _M)
-	-- Test stanza
-	local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
-		:tag("child1");
-	-- Make reply stanza
-	local r = error_reply(s);
-	assert_equal(r.name, s.name);
-	assert_equal(r.id, s.id);
-	assert_equal(r.attr.to, s.attr.from);
-	assert_equal(r.attr.from, s.attr.to);
-	assert_equal(#r.tags, 1);
-	
-	-- Test stanza
-	local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
-		:tag("child1");
-	-- Make reply stanza
-	local r = error_reply(s);
-	assert_equal(r.name, s.name);
-	assert_equal(r.id, s.id);
-	assert_equal(r.attr.to, s.attr.from);
-	assert_equal(r.attr.from, s.attr.to);
-	assert_equal(r.attr.type, "error");
-	assert_equal(#r.tags, 1);
+	do
+		-- Test stanza
+		local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
+			:tag("child1");
+		-- Make reply stanza
+		local r = error_reply(s);
+		assert_equal(r.name, s.name);
+		assert_equal(r.id, s.id);
+		assert_equal(r.attr.to, s.attr.from);
+		assert_equal(r.attr.from, s.attr.to);
+		assert_equal(#r.tags, 1);
+	end
+
+	do
+		-- Test stanza
+		local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
+			:tag("child1");
+		-- Make reply stanza
+		local r = error_reply(s);
+		assert_equal(r.name, s.name);
+		assert_equal(r.id, s.id);
+		assert_equal(r.attr.to, s.attr.from);
+		assert_equal(r.attr.from, s.attr.to);
+		assert_equal(r.attr.type, "error");
+		assert_equal(#r.tags, 1);
+	end
 end