summaryrefslogtreecommitdiff
path: root/tests/core/test_backgrounding.py
blob: 55c4ba7383dfa8673826c460aa3f248e14cee748 (plain)
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
import unittest
import threading
import dogpile.core


class TestAsyncRunner(unittest.TestCase):
    def test_async_release(self):
        self.called = False

        def runner(mutex):
            self.called = True
            mutex.release()

        mutex = threading.Lock()
        create = lambda: ("value", 1)
        get = lambda: ("value", 1)
        expiretime = 1

        assert not self.called

        with dogpile.core.Lock(mutex, create, get, expiretime, runner) as l:
            assert self.called

        assert self.called

if __name__ == '__main__':
    unittest.main()