Beispiel #1
0
    def test_acquireLeaseTimeout(self):
        """Test that getTimeout correctly calculates value from lease.

        The imprecision is because leases are relative to the current time,
        and the current time may have changed by the time we get to
        job.getTimeout() <= 300.
        """
        job = Job()
        job.acquireLease(300)
        self.assertTrue(job.getTimeout() > 0)
        self.assertTrue(job.getTimeout() <= 300)
Beispiel #2
0
class StuckJob(StaticJobSource):
    """Simulation of a job that stalls."""
    implements(IRunnableJob)

    done = False

    # A list of jobs to run: id, lease_length, delay.
    #
    # For the first job, have a very long lease, so that it
    # doesn't expire and so we soak up the ZCML loading time.  For the
    # second job, have a short lease so we hit the timeout.
    jobs = [
        (10000, 0),
        (5, 30),
    ]

    def __init__(self, id, lease_length, delay):
        self.id = id
        self.lease_length = lease_length
        self.delay = delay
        self.job = Job()

    def __repr__(self):
        return '<%s(%r, lease_length=%s, delay=%s)>' % (
            self.__class__.__name__, self.id, self.lease_length, self.delay)

    def acquireLease(self):
        return self.job.acquireLease(self.lease_length)

    def run(self):
        sleep(self.delay)
class StuckJob(StaticJobSource):
    """Simulation of a job that stalls."""
    implements(IRunnableJob)

    done = False

    # A list of jobs to run: id, lease_length, delay.
    #
    # For the first job, have a very long lease, so that it
    # doesn't expire and so we soak up the ZCML loading time.  For the
    # second job, have a short lease so we hit the timeout.
    jobs = [
        (10000, 0),
        (5, 30),
        ]

    def __init__(self, id, lease_length, delay):
        self.id = id
        self.lease_length = lease_length
        self.delay = delay
        self.job = Job()

    def __repr__(self):
        return '<%s(%r, lease_length=%s, delay=%s)>' % (
            self.__class__.__name__, self.id, self.lease_length, self.delay)

    def acquireLease(self):
        return self.job.acquireLease(self.lease_length)

    def run(self):
        sleep(self.delay)
Beispiel #4
0
 def test_acquireLeaseTimeoutExpired(self):
     """Expired leases don't produce negative timeouts."""
     job = Job()
     job.acquireLease(-300)
     self.assertEqual(0, job.getTimeout())
Beispiel #5
0
 def test_acquireStaleLease(self):
     """Job.acquireLease should work when a lease is expired."""
     job = Job()
     job.acquireLease(-1)
     job.acquireLease()
Beispiel #6
0
 def test_acquireHeldLease(self):
     """Job.acquireLease should raise LeaseHeld if repeated."""
     job = Job()
     job.acquireLease()
     self.assertRaises(LeaseHeld, job.acquireLease)
Beispiel #7
0
 def test_acquireLease(self):
     """Job.acquireLease should set job.lease_expires."""
     job = Job()
     job.acquireLease()
     self.assertIsNot(None, job.lease_expires)