Skip to content

Commit b9e96fa

Browse files
committed
Add tests on the capped queue
1 parent 91398cd commit b9e96fa

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/test_core.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from unittest.mock import patch
2+
from queue import Queue
3+
from howfast_apm import core
4+
5+
6+
def test_capped_queue(example_queue_items_gen):
7+
""" CoreAPM.save_point should add items in the queue """
8+
# TODO: find a better way to replace this queue object
9+
core.queue = Queue(maxsize=10)
10+
# Save one point
11+
assert core.queue.qsize() == 0
12+
core.CoreAPM.save_point(*next(example_queue_items_gen))
13+
assert core.queue.qsize() == 1
14+
15+
# Save a second point
16+
core.CoreAPM.save_point(*next(example_queue_items_gen))
17+
assert core.queue.qsize() == 2
18+
19+
# Fill the queue
20+
for i in range(8):
21+
item = list(next(example_queue_items_gen))
22+
item[3] = f'/call/{i}' # update the URL to keep track of points
23+
core.CoreAPM.save_point(*item)
24+
assert core.queue.qsize() == 10
25+
assert core.queue.full()
26+
27+
next_item = core.queue.get_nowait()
28+
assert next_item
29+
30+
31+
def test_capped_queue_full(example_queue_item):
32+
""" CoreAPM.save_point should discard old items should the queue be full """
33+
# TODO: find a better way to replace this queue object
34+
core.queue = Queue(maxsize=10)
35+
# Fill the queue
36+
for i in range(10):
37+
item = list(example_queue_item)
38+
item[3] = f'/call/{i}' # update the URL to keep track of points
39+
core.CoreAPM.save_point(*item)
40+
assert core.queue.full()
41+
42+
# Add one more item to the full queue
43+
core.CoreAPM.save_point(*example_queue_item)
44+
assert core.queue.full(), 'queue should still be full'
45+
assert core.queue.qsize() == 10

0 commit comments

Comments
 (0)