Software /
code /
prosody
Annotate
spec/util_smqueue_spec.lua @ 13571:ca041359c045
net.server_epoll: Don't try to flush buffer on closed connections
Attempt to fix a bug where connections are somehow closed twice, leading
to bad things happening elsewhere.
With LuaSec, closed connections are generally already too closed to
write anything to anyway since it does not support unidirectional
shutdown.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 19 Nov 2024 00:41:02 +0100 (8 months ago) |
parent | 12778:6163c8b17ea9 |
rev | line source |
---|---|
12055
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 describe("util.smqueue", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local smqueue |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 setup(function() smqueue = require "util.smqueue"; end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 describe("#new()", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 it("should work", function() |
12778 | 8 assert.has_error(function () smqueue.new(-1) end); |
9 assert.has_error(function () smqueue.new(0) end); | |
10 assert.not_has_error(function () smqueue.new(1) end); | |
12055
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local q = smqueue.new(10); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 assert.truthy(q); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 describe("#push()", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 it("should allow pushing many items", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local q = smqueue.new(10); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 for i = 1, 20 do q:push(i); end |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 assert.equal(20, q:count_unacked()); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 describe("#resumable()", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 it("returns true while the queue is small", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 local q = smqueue.new(10); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 for i = 1, 10 do q:push(i); end |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 assert.truthy(q:resumable()); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 q:push(11); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 assert.falsy(q:resumable()); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 describe("#ack", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 it("allows removing items", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 local q = smqueue.new(10); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 for i = 1, 10 do q:push(i); end |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 assert.same({ 1; 2; 3 }, q:ack(3)); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 assert.same({ 4; 5; 6 }, q:ack(6)); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 assert.falsy(q:ack(3), "can't go backwards") |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 assert.falsy(q:ack(100), "can't ack too many") |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 for i = 11, 20 do q:push(i); end |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 assert.same({ 11; 12 }, q:ack(12), "items are dropped"); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 describe("#resume", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 it("iterates over current items", function() |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 local q = smqueue.new(10); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 for i = 1, 12 do q:push(i); end |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 assert.same({ 3; 4; 5; 6 }, q:ack(6)); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 assert.truthy(q:resumable()); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 local resume = {} |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 for _, i in q:resume() do resume[i] = true end |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 assert.same({ [7] = true; [8] = true; [9] = true; [10] = true; [11] = true; [12] = true }, resume); |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 end) |
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 end) |
12058
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
58 |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
59 describe("#table", function () |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
60 it("produces a compat layer", function () |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
61 local q = smqueue.new(10); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
62 for i = 1,10 do q:push(i); end |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
63 do |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
64 local t = q:table(); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
65 assert.same({ 1; 2; 3; 4; 5; 6; 7; 8; 9; 10 }, t); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
66 end |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
67 do |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
68 for i = 11,20 do q:push(i); end |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
69 local t = q:table(); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
70 assert.same({ 11; 12; 13; 14; 15; 16; 17; 18; 19; 20 }, t); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
71 end |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
72 do |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
73 q:ack(15); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
74 local t = q:table(); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
75 assert.same({ 16; 17; 18; 19; 20 }, t); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
76 end |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
77 do |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
78 q:ack(20); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
79 local t = q:table(); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
80 assert.same({}, t); |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
81 end |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
82 end) |
4860da718e87
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12055
diff
changeset
|
83 end) |
12055
daced16154fa
util.smqueue: Abstract queue with acknowledgements and overflow
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 end); |