~lutostag/ubuntu/trusty/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/maasserver/utils/tests/test_utils.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-03-28 10:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20140328104353-ekpolg0pm5xnvq2s
Tags: upstream-1.5+bzr2204
ImportĀ upstreamĀ versionĀ 1.5+bzr2204

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
__all__ = []
16
16
 
17
17
import httplib
 
18
import threading
18
19
from urllib import urlencode
19
20
 
20
21
from django.conf import settings
36
37
    get_local_cluster_UUID,
37
38
    map_enum,
38
39
    strip_domain,
 
40
    synchronised,
39
41
    )
40
42
from maastesting.testcase import MAASTestCase
 
43
from mock import sentinel
41
44
from netaddr import IPNetwork
42
45
 
43
46
 
292
295
            network=IPNetwork("192.168.41.0/24"))
293
296
        self.assertEqual(
294
297
            nodegroup1, find_nodegroup(get_request('192.168.41.199')))
 
298
 
 
299
 
 
300
class TestSynchronised(MAASTestCase):
 
301
 
 
302
    def test_locks_when_calling(self):
 
303
        lock = threading.Lock()
 
304
 
 
305
        @synchronised(lock)
 
306
        def example_synchronised_function():
 
307
            self.assertTrue(lock.locked())
 
308
            return sentinel.called
 
309
 
 
310
        self.assertFalse(lock.locked())
 
311
        self.assertEqual(sentinel.called, example_synchronised_function())
 
312
        self.assertFalse(lock.locked())