Esempio n. 1
0
    def test_resource_can_be_retaken_by_same_priority(self):
        r = Resource()

        handle = r.request(priority_high)
        handle2 = r.request(priority_high)

        self.assertEqual(handle, handle2)
Esempio n. 2
0
    def test_resource_handle_needed_to_release(self):
        r = Resource()

        handle = r.request(priority_low)
        handle2 = r.request(priority_high)
        r.release(handle)
        handle3 = r.request(priority_low)
        self.assertIsNone(handle3)
        self.assertEqual(False, handle2.is_interrupted)
Esempio n. 3
0
    def test_lower_priority_can_take_resource_after_higher_priority_releases(self):
        r = Resource()

        handle = r.request(priority_high)
        handle.release()
        handle2 = r.request(priority_low)
        self.assertTrue(handle)
        self.assertFalse(handle.is_interrupted)
        self.assertTrue(handle2)
Esempio n. 4
0
    def test_higher_priority_handle_can_not_be_taken_taken_away(self):
        r = Resource()

        mock = Mock()
        handle = r.request(priority_high, mock)
        handle2 = r.request(priority_low)
        self.assertIsNotNone(handle)
        self.assertEqual(False, handle.is_interrupted)
        self.assertIsNone(handle2)
        self.assertEqual(0, mock.call_count)
Esempio n. 5
0
    def test_lower_priority_handle_can_be_taken_taken_away(self):
        r = Resource()

        mock = Mock()
        handle = r.request(priority_low, mock)
        handle2 = r.request(priority_high)
        self.assertTrue(handle)
        self.assertTrue(handle.is_interrupted)
        self.assertTrue(handle2)
        self.assertEqual(1, mock.call_count)
Esempio n. 6
0
    def test_run_should_only_run_on_active_handle(self):
        r = Resource()

        mock = Mock()

        handle = r.request(priority_low)
        handle2 = r.request(priority_high)

        handle2.run_uninterruptable(mock)
        handle.run_uninterruptable(lambda: self.fail('This should not run'))
        self.assertEqual(1, mock.call_count)
Esempio n. 7
0
    def test_resource_can_be_retaken_by_same_priority(self):
        r = Resource()

        handle = r.request(priority_high)
        handle2 = r.request(priority_high)

        self.assertTrue(handle)
        self.assertTrue(handle2)

        self.assertTrue(handle.is_interrupted)
        self.assertFalse(handle2.is_interrupted)
Esempio n. 8
0
    def test_empty_resource_can_be_taken(self):
        r = Resource()

        handle = r.request()
        self.assertIsNotNone(handle)