Software /
code /
prosody
Annotate
tests/test_util_queue.lua @ 7559:b1b27dedf4cf
net.server_epoll: Replace any previous pausefor timer
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Aug 2016 01:11:59 +0200 |
parent | 7509:d4bd036e679b |
rev | line source |
---|---|
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
2 function new(new) |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
3 do |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
4 local q = new(10); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
6 assert_equal(q.size, 10); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
7 assert_equal(q:count(), 0); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
9 assert_is(q:push("one")); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
10 assert_is(q:push("two")); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
11 assert_is(q:push("three")); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
13 for i = 4, 10 do |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
14 assert_is(q:push("hello")); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
15 assert_equal(q:count(), i, "count is not "..i.."("..q:count()..")"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
16 end |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
17 assert_equal(q:push("hello"), nil, "queue overfull!"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
18 assert_equal(q:push("hello"), nil, "queue overfull!"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
19 assert_equal(q:pop(), "one", "queue item incorrect"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
20 assert_equal(q:pop(), "two", "queue item incorrect"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
21 assert_is(q:push("hello")); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
22 assert_is(q:push("hello")); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
23 assert_equal(q:pop(), "three", "queue item incorrect"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
24 assert_is(q:push("hello")); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
25 assert_equal(q:push("hello"), nil, "queue overfull!"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
26 assert_equal(q:push("hello"), nil, "queue overfull!"); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
28 assert_equal(q:count(), 10, "queue count incorrect"); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
30 for _ = 1, 10 do |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
31 assert_equal(q:pop(), "hello", "queue item incorrect"); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
32 end |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
33 |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
34 assert_equal(q:count(), 0, "queue count incorrect"); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
36 assert_is(q:push(1)); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
37 for i = 1, 1001 do |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
38 assert_equal(q:pop(), i); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
39 assert_equal(q:count(), 0); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
40 assert_is(q:push(i+1)); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
41 assert_equal(q:count(), 1); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
42 end |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
43 assert_equal(q:pop(), 1002); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
44 assert_is(q:push(1)); |
7508
736dea7b99ec
test_util_queue: Reduce iteration count of loop and add asserts
Kim Alvefur <zash@zash.se>
parents:
7507
diff
changeset
|
45 for i = 1, 1000 do |
736dea7b99ec
test_util_queue: Reduce iteration count of loop and add asserts
Kim Alvefur <zash@zash.se>
parents:
7507
diff
changeset
|
46 assert_equal(q:pop(), i); |
736dea7b99ec
test_util_queue: Reduce iteration count of loop and add asserts
Kim Alvefur <zash@zash.se>
parents:
7507
diff
changeset
|
47 assert_is(q:push(i+1)); |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
48 end |
7509
d4bd036e679b
test_util_queue: finish stress-test by emptying the queue
Anton Shestakov <av6@dwimlabs.net>
parents:
7508
diff
changeset
|
49 assert_equal(q:pop(), 1001); |
d4bd036e679b
test_util_queue: finish stress-test by emptying the queue
Anton Shestakov <av6@dwimlabs.net>
parents:
7508
diff
changeset
|
50 assert_equal(q:count(), 0); |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
51 end |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
53 do |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
54 -- Test queues that purge old items when pushing to a full queue |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
55 local q = new(10, true); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
57 for i = 1, 10 do |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
58 q:push(i); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
59 end |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
61 assert_equal(q:count(), 10); |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
63 assert_is(q:push(11)); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
64 assert_equal(q:count(), 10); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
65 assert_equal(q:pop(), 2); -- First item should have been purged |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 |
7507
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
67 for i = 12, 32 do |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
68 assert_is(q:push(i)); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
69 end |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
70 |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
71 assert_equal(q:count(), 10); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
72 assert_equal(q:pop(), 23); |
11e8c605a591
tests: Adapt test for util.queue to the test framework
Kim Alvefur <zash@zash.se>
parents:
6732
diff
changeset
|
73 end |
6732
b5cf091d8c45
tests: Add tests for util.queue
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 end |