File: TestSynchronousQueue.py

package info (click to toggle)
python-applicationinsights 0.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 608 kB
  • ctags: 801
  • sloc: python: 4,572; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import unittest

import sys, os, os.path
rootDirectory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..')
if rootDirectory not in sys.path:
    sys.path.append(rootDirectory)

from applicationinsights import channel

class TestSynchronousQueue(unittest.TestCase):
    def test_construct(self):
        actual = channel.SynchronousQueue(MockSynchronousSender())
        self.assertIsNotNone(actual)

    def test_flush_works_as_expected(self):
        sender = MockSynchronousSender()
        queue = channel.SynchronousQueue(sender)
        queue.max_queue_length = 3
        for i in range(1, 8):
            queue.put(i)
        self.assertEqual([[1, 2], [3], [4, 5], [6]], sender.data)
        temp = []
        while queue._queue.qsize() > 0:
            temp.append(queue._queue.get())
        self.assertEqual([7], temp)


class MockSynchronousSender:
    def __init__(self):
        self.send_buffer_size = 2
        self.data = []
        self.queue = None

    def send(self, data_to_send):
        self.data.append(data_to_send)