Ejemplo n.º 1
0
    def test_lock_used(self):
        resource = ResourceFile(self.lockfile)
        child = os.fork()
        if not child:
            # Child grabs resource and sleeps until killed.
            with resource:
                resource.acquire({'pid': os.getpid()})
            while True:
                time.sleep(5)

        time.sleep(0.2)
        with resource:
            used = resource.used()
            self.assert_(used)
            self.assertEquals(used['pid'], child)

        os.kill(child, signal.SIGTERM)
        os.waitpid(child, 0)
Ejemplo n.º 2
0
    def test_lock_used(self):
        resource = ResourceFile(self.lockfile)
        child = os.fork()
        if not child:
            # Child grabs resource and sleeps until killed.
            with resource:
                resource.acquire({'pid': os.getpid()})
            while True:
                time.sleep(5)

        time.sleep(0.2)
        with resource:
            used = resource.used()
            self.assert_(used)
            self.assertEquals(used['pid'], child)

        os.kill(child, signal.SIGTERM)
        os.waitpid(child, 0)
Ejemplo n.º 3
0
    def test_interruptible_claim(self):
        resource = ResourceFile(self.lockfile)
        child = os.fork()
        if not child:
            # Child grabs resource and sleeps until killed.
            with resource:
                resource.acquire({'pid': os.getpid(),
                                  'uri': 'child'})
            time.sleep(2)

            with resource:
                resource.acquire({'interruptible': True})

            while(True):
                time.sleep(0.5)
        else:
            self.children.append(child)

        # This is racy. Child is originally uninterruptible, but after a short
        # sleep, he marks himself interruptible
        time.sleep(1)
        info = {'uri': 'parent', 'pid': os.getpid()}
        self.assertRaises(HTTPConflict, claim, resource, info)
        time.sleep(2)
        claim(resource, info)
        time.sleep(1)
        # should be killed by now.
        pid, status = os.waitpid(child, os.WNOHANG)
        self.assertEquals(pid, child)
        with resource:
            used = resource.used()
            self.assert_(used)
            self.assertEquals(used['pid'], os.getpid())
            self.assertEquals(used['uri'], 'parent')
            # Bug: lock.acquire only updates the keys you give it.
            # So I'm marked interruptible unknowingly.
            # lunr.storage.controller.base.inspect was updated to always
            # set interruptible to False because of this.
            self.assertEquals(used['interruptible'], True)