def test_calculate_with_timeout_tries_to_interrupt_timed_out_thread(
        self, mock_sleep, mock_ithread_class
    ):
        def check_interrupt_called_first(_):
            self.assertTrue(mock_ithread.interrupt.called)
        mock_sleep.side_effect = check_interrupt_called_first

        mock_ithread_class.return_value = mock_ithread = Mock()
        def set_is_alive():
            mock_ithread.alive = not mock_ithread.alive
            return not mock_ithread.alive
        mock_ithread.isAlive.side_effect = set_is_alive

        calculate_with_timeout(
            sentinel.worksheet, sentinel.usercode,
            sentinel.timeout_seconds, sentinel.private_key
        )
        self.assertEquals(mock_ithread.method_calls,
                          [
                              ('start', (), {}),
                              ('join', (sentinel.timeout_seconds,), {}),
                              ('isAlive', (), {}),
                              ('interrupt', (), {}),
                              ('isAlive', (), {}),
                              ]
                          )
        self.assertEquals(mock_sleep.call_args, ((0.1,), {}))
Example #2
0
    def test_calculate_with_timeout_tries_to_interrupt_timed_out_thread(
            self, mock_sleep, mock_ithread_class):
        def check_interrupt_called_first(_):
            self.assertTrue(mock_ithread.interrupt.called)

        mock_sleep.side_effect = check_interrupt_called_first

        mock_ithread_class.return_value = mock_ithread = Mock()

        def set_is_alive():
            mock_ithread.alive = not mock_ithread.alive
            return not mock_ithread.alive

        mock_ithread.isAlive.side_effect = set_is_alive

        calculate_with_timeout(sentinel.worksheet, sentinel.usercode,
                               sentinel.timeout_seconds, sentinel.private_key)
        self.assertEquals(mock_ithread.method_calls, [
            ('start', (), {}),
            ('join', (sentinel.timeout_seconds, ), {}),
            ('isAlive', (), {}),
            ('interrupt', (), {}),
            ('isAlive', (), {}),
        ])
        self.assertEquals(mock_sleep.call_args, ((0.1, ), {}))
Example #3
0
    def test_calculate_with_timeout_calls_calculate_function_with_contents_and_usercode(
            self, mock_calculate):
        long_timeout_seconds = 100
        calculate_with_timeout(sentinel.worksheet, sentinel.usercode,
                               long_timeout_seconds, sentinel.private_key)

        self.assertEquals(mock_calculate.call_args,
                          ((sentinel.worksheet, sentinel.usercode,
                            sentinel.private_key), {}))
Example #4
0
 def test_calculate_with_timeout_uses_interruptable_thread_with_correct_timeout(
         self, mock_ithread_class):
     mock_ithread_class.return_value = mock_ithread = Mock()
     mock_ithread.isAlive.return_value = False
     calculate_with_timeout(sentinel.worksheet, sentinel.usercode,
                            sentinel.timeout_seconds, sentinel.private_key)
     self.assertEquals(mock_ithread.method_calls, [
         ('start', (), {}),
         ('join', (sentinel.timeout_seconds, ), {}),
         ('isAlive', (), {}),
     ])
    def test_calculate_with_timeout_calls_calculate_function_with_contents_and_usercode(
        self, mock_calculate
    ):
        long_timeout_seconds = 100
        calculate_with_timeout(
            sentinel.worksheet, sentinel.usercode,
            long_timeout_seconds, sentinel.private_key
        )

        self.assertEquals(
            mock_calculate.call_args,
            ((sentinel.worksheet, sentinel.usercode, sentinel.private_key), {})
        )
 def test_calculate_with_timeout_uses_interruptable_thread_with_correct_timeout(
     self, mock_ithread_class
 ):
     mock_ithread_class.return_value = mock_ithread = Mock()
     mock_ithread.isAlive.return_value = False
     calculate_with_timeout(
         sentinel.worksheet, sentinel.usercode,
         sentinel.timeout_seconds, sentinel.private_key
     )
     self.assertEquals(mock_ithread.method_calls,
                       [
                           ('start', (), {}),
                           ('join', (sentinel.timeout_seconds,), {}),
                           ('isAlive', (), {}),
                           ]
                       )