Software /
code /
prosody
Annotate
spec/util_rsm_spec.lua @ 12468:353836684009
net.connect: Fix accumulation of connection attempt references
Connection attempts that failed the Happy Eyeballs race were not
unreferenced and would accumulate.
Tested by inspecting the 'pending_connections_map' after establishing
s2s with a s2s target where the IPv6 port has a -j DROP rule causing it
to time out and the IPv4 attempt wins the race.
Expected is that the losing connection stays around until net.server
timeouts kick in where it should be removed. The map table should tend
towards being empty during idle times.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 20 Apr 2022 22:41:54 +0200 |
parent | 11427:83f5499d1f10 |
rev | line source |
---|---|
10760 | 1 local rsm = require "util.rsm"; |
2 local xml = require "util.xml"; | |
3 | |
4 local function strip(s) | |
5 return (s:gsub(">%s+<", "><")); | |
6 end | |
7 | |
8 describe("util.rsm", function () | |
9 describe("parse", function () | |
10 it("works", function () | |
11 local test = xml.parse(strip([[ | |
12 <set xmlns='http://jabber.org/protocol/rsm'> | |
13 <max>10</max> | |
14 </set> | |
15 ]])); | |
16 assert.same({ max = 10 }, rsm.parse(test)); | |
17 end); | |
18 | |
19 it("works", function () | |
20 local test = xml.parse(strip([[ | |
21 <set xmlns='http://jabber.org/protocol/rsm'> | |
22 <first index='0'>saint@example.org</first> | |
23 <last>peterpan@neverland.lit</last> | |
24 <count>800</count> | |
25 </set> | |
26 ]])); | |
27 assert.same({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }, rsm.parse(test)); | |
28 end); | |
29 | |
30 it("works", function () | |
31 local test = xml.parse(strip([[ | |
32 <set xmlns='http://jabber.org/protocol/rsm'> | |
33 <max>10</max> | |
34 <before>peter@pixyland.org</before> | |
35 </set> | |
36 ]])); | |
37 assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test)); | |
38 end); | |
39 | |
11427
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
40 it("all fields works", function() |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
41 local test = assert(xml.parse(strip([[ |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
42 <set xmlns='http://jabber.org/protocol/rsm'> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
43 <after>a</after> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
44 <before>b</before> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
45 <count>10</count> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
46 <first index='1'>f</first> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
47 <index>5</index> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
48 <last>z</last> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
49 <max>100</max> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
50 </set> |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
51 ]]))); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
52 assert.same({ |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
53 after = "a"; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
54 before = "b"; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
55 count = 10; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
56 first = {index = 1; "f"}; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
57 index = 5; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
58 last = "z"; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
59 max = 100; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
60 }, rsm.parse(test)); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
61 end); |
10760 | 62 end); |
63 | |
64 describe("generate", function () | |
65 it("works", function () | |
66 local test = xml.parse(strip([[ | |
67 <set xmlns='http://jabber.org/protocol/rsm'> | |
68 <max>10</max> | |
69 </set> | |
70 ]])); | |
71 local res = rsm.generate({ max = 10 }); | |
72 assert.same(test:get_child_text("max"), res:get_child_text("max")); | |
73 end); | |
74 | |
75 it("works", function () | |
76 local test = xml.parse(strip([[ | |
77 <set xmlns='http://jabber.org/protocol/rsm'> | |
78 <first index='0'>saint@example.org</first> | |
79 <last>peterpan@neverland.lit</last> | |
80 <count>800</count> | |
81 </set> | |
82 ]])); | |
83 local res = rsm.generate({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }); | |
84 assert.same(test:get_child("first").attr.index, res:get_child("first").attr.index); | |
85 assert.same(test:get_child_text("first"), res:get_child_text("first")); | |
86 assert.same(test:get_child_text("last"), res:get_child_text("last")); | |
87 assert.same(test:get_child_text("count"), res:get_child_text("count")); | |
88 end); | |
89 | |
90 it("works", function () | |
91 local test = xml.parse(strip([[ | |
92 <set xmlns='http://jabber.org/protocol/rsm'> | |
93 <max>10</max> | |
94 <before>peter@pixyland.org</before> | |
95 </set> | |
96 ]])); | |
97 local res = rsm.generate({ max = 10, before = "peter@pixyland.org" }); | |
98 assert.same(test:get_child_text("max"), res:get_child_text("max")); | |
99 assert.same(test:get_child_text("before"), res:get_child_text("before")); | |
100 end); | |
101 | |
10762
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
102 it("handles floats", function () |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
103 local r1 = rsm.generate({ max = 10.0, count = 100.0, first = { index = 1.0, "foo" } }); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
104 assert.equal("10", r1:get_child_text("max")); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
105 assert.equal("100", r1:get_child_text("count")); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
106 assert.equal("1", r1:get_child("first").attr.index); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
107 end); |
4fc224c97986
util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents:
10760
diff
changeset
|
108 |
11427
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
109 |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
110 it("all fields works", function () |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
111 local res = rsm.generate({ |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
112 after = "a"; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
113 before = "b"; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
114 count = 10; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
115 first = {index = 1; "f"}; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
116 index = 5; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
117 last = "z"; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
118 max = 100; |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
119 }); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
120 assert.equal("a", res:get_child_text("after")); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
121 assert.equal("b", res:get_child_text("before")); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
122 assert.equal("10", res:get_child_text("count")); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
123 assert.equal("f", res:get_child_text("first")); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
124 assert.equal("1", res:get_child("first").attr.index); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
125 assert.equal("5", res:get_child_text("index")); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
126 assert.equal("z", res:get_child_text("last")); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
127 assert.equal("100", res:get_child_text("max")); |
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
128 end); |
10760 | 129 end); |
11427
83f5499d1f10
util.rsm: Increase test coverage
Kim Alvefur <zash@zash.se>
parents:
10762
diff
changeset
|
130 |
10760 | 131 end); |
132 |