def test_add_task(self):

        mock_timer1 = self.ws._timer_run_next_task
        mock_timer2 = self.ws._timer_count_pending_requests

        host = "abc.xyz"
        port = 80
        request = WSRequest("", host, port, "", None)
        key = request.get_host_key()

        self.ws.add_task(0, request)
        request.priority = True
        self.ws.add_task(0, request)
        request.important = True
        self.ws.add_task(1, request)

        # Test if timer start was called in case it was inactive
        mock_timer1.isActive.return_value = False
        mock_timer2.isActive.return_value = False
        request.priority = False
        self.ws.add_task(1, request)
        self.assertIn('start', repr(mock_timer1.method_calls))

        # Test if key was added to prio queue
        self.assertEqual(len(self.ws._queues[1]), 1)
        self.assertIn(key, self.ws._queues[1])

        # Test if 2 requests were added in prio queue
        self.assertEqual(len(self.ws._queues[1][key]), 2)

        # Test if important request was added ahead in the queue
        self.assertEqual(self.ws._queues[0][key][0], 1)
    def test_add_task(self):

        mock_timer1 = self.ws._timer_run_next_task
        mock_timer2 = self.ws._timer_count_pending_requests

        host = "abc.xyz"
        port = 80
        request = WSRequest("", host, port, "", None)
        key = request.get_host_key()

        self.ws.add_task(0, request)
        request.priority = True
        self.ws.add_task(0, request)
        request.important = True
        self.ws.add_task(1, request)

        # Test if timer start was called in case it was inactive
        mock_timer1.isActive.return_value = False
        mock_timer2.isActive.return_value = False
        request.priority = False
        self.ws.add_task(1, request)
        self.assertIn('start', repr(mock_timer1.method_calls))

        # Test if key was added to prio queue
        self.assertEqual(len(self.ws._queues[1]), 1)
        self.assertIn(key, self.ws._queues[1])

        # Test if 2 requests were added in prio queue
        self.assertEqual(len(self.ws._queues[1][key]), 2)

        # Test if important request was added ahead in the queue
        self.assertEqual(self.ws._queues[0][key][0], 1)
Exemple #3
0
 def test_add_task(self):
     request = WSRequest("", "abc.xyz", 80, "", None)
     func = 1
     task = self.ws.add_task(func, request)
     self.assertEqual((request.get_host_key(), func, 0), task)
     self.ws._queue.add_task.assert_called_with(task, False)
     request.important = True
     task = self.ws.add_task(func, request)
     self.ws._queue.add_task.assert_called_with(task, True)