コード例 #1
0
    def test_context_manager(self):
        p = CMDB()
        p.saveObject(self.cmdbobject, 456)

        with p(self.cmdbobject) as value:
            self.assertEquals(value, 456)
            p.saveObject(self.cmdbobject, 123)

        self.assert_(not p.pm_isLocked(self.cmdbobject))

        self.assertRaises(ObjectNotOwnedException,
                p.saveObject, self.cmdbobject, 456)
コード例 #2
0
    def test_context_manager(self):
        p = CMDB()
        p.saveObject(self.cmdbobject, 456)

        with p(self.cmdbobject) as value:
            self.assertEquals(value, 456)
            p.saveObject(self.cmdbobject, 123)

        self.assert_(not p.pm_isLocked(self.cmdbobject))

        self.assertRaises(ObjectNotOwnedException, p.saveObject,
                          self.cmdbobject, 456)
コード例 #3
0
    def test_timeout(self):
        p = CMDB()

        p.saveObject(self.cmdbobject, 123)

        def run():
            p.getObjectWithLock(self.cmdbobject, locktimeout=3)
            time.sleep(3)

        t1 = threading.Thread(target=run)

        t1.start()
        time.sleep(1)

        self.assert_(p.pm_isLocked(self.cmdbobject))

        start = time.time()
        p.getObjectWithLock(self.cmdbobject)
        end = time.time()

        #end - start must be somewhere close to 3
        self.assert_(end - start > 2)
        self.assert_(end - start < 4)
コード例 #4
0
    def test_timeout(self):
        p = CMDB()

        p.saveObject(self.cmdbobject, 123)

        def run():
            p.getObjectWithLock(self.cmdbobject, locktimeout=3)
            time.sleep(3)

        t1 = threading.Thread(target=run)

        t1.start()
        time.sleep(1)

        self.assert_(p.pm_isLocked(self.cmdbobject))

        start = time.time()
        p.getObjectWithLock(self.cmdbobject)
        end = time.time()

        #end - start must be somewhere close to 3
        self.assert_(end - start > 2)
        self.assert_(end - start < 4)