mirror of
https://github.com/optim-enterprises-bv/patroni.git
synced 2026-01-11 18:35:15 +00:00
Besides that: 1. Introduce `setup.py isort` for quick check 2. Introduce GH actions to check imports
34 lines
766 B
Python
34 lines
766 B
Python
import unittest
|
|
|
|
from threading import Thread
|
|
from unittest.mock import Mock, patch
|
|
|
|
from patroni.async_executor import AsyncExecutor, CriticalTask
|
|
|
|
|
|
class TestAsyncExecutor(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.a = AsyncExecutor(Mock(), Mock())
|
|
|
|
@patch.object(Thread, 'start', Mock())
|
|
def test_run_async(self):
|
|
self.a.run_async(Mock(return_value=True))
|
|
|
|
def test_run(self):
|
|
self.a.run(Mock(side_effect=Exception()))
|
|
|
|
def test_cancel(self):
|
|
self.a.cancel()
|
|
self.a.schedule('foo')
|
|
self.a.cancel()
|
|
self.a.run(Mock())
|
|
|
|
|
|
class TestCriticalTask(unittest.TestCase):
|
|
|
|
def test_completed_task(self):
|
|
ct = CriticalTask()
|
|
ct.complete(1)
|
|
self.assertFalse(ct.cancel())
|