Annotate

tests/test_util_queue.lua @ 6846:7eb166fa1f26

mod_c2s, mod_s2s: Close incoming connections if there are no features to offer on incomplete streams (fixes #285)
author Kim Alvefur <zash@zash.se>
date Thu, 24 Sep 2015 20:05:23 +0200
parent 6732:b5cf091d8c45
child 7507:11e8c605a591
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6732
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local new = require "util.queue".new;
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local q = new(10);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 assert(q.size == 10);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 assert(q:count() == 0);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 assert(q:push("one"));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 assert(q:push("two"));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 assert(q:push("three"));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 for i = 4, 10 do
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 print("pushing "..i)
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 assert(q:push("hello"));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 assert(q:count() == i, "count is not "..i.."("..q:count()..")");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 assert(q:push("hello") == nil, "queue overfull!");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 assert(q:push("hello") == nil, "queue overfull!");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 assert(q:pop() == "one", "queue item incorrect");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 assert(q:pop() == "two", "queue item incorrect");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 assert(q:push("hello"));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 assert(q:push("hello"));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 assert(q:pop() == "three", "queue item incorrect");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 assert(q:push("hello"));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 assert(q:push("hello") == nil, "queue overfull!");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 assert(q:push("hello") == nil, "queue overfull!");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 assert(q:count() == 10, "queue count incorrect");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 for i = 1, 10 do
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 assert(q:pop() == "hello", "queue item incorrect");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 assert(q:count() == 0, "queue count incorrect");
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 assert(q:push(1));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 for i = 1, 1001 do
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 assert(q:pop() == i);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 assert(q:count() == 0);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 assert(q:push(i+1));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 assert(q:count() == 1);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 assert(q:pop() == 1002);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 assert(q:push(1));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 for i = 1, 1000000 do
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 q:pop();
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 q:push(i+1);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 -- Test queues that purge old items when pushing to a full queue
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 local q = new(10, true);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 for i = 1, 10 do
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 q:push(i);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 end
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 assert(q:count() == 10);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 assert(q:push(11));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 assert(q:count() == 10);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 assert(q:pop() == 2); -- First item should have been purged
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 for i = 12, 32 do
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 assert(q:push(i));
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 end
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 assert(q:count() == 10);
b5cf091d8c45 tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 assert(q:pop() == 23);