本文整理汇总了Python中buildbot.locks.WorkerLock类的典型用法代码示例。如果您正苦于以下问题:Python WorkerLock类的具体用法?Python WorkerLock怎么用?Python WorkerLock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkerLock类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testStopBuildWaitingForStepLocks
def testStopBuildWaitingForStepLocks(self):
b = self.build
lock = WorkerLock('lock')
lock_access = lock.access('counting')
lock.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(lock) \
.getLock(self.workerforbuilder.worker)
step = LoggingBuildStep(locks=[lock_access])
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), lock.access('counting'))
gotLocks = [False]
def acquireLocks(res=None):
gotLocks[0] = True
retval = LoggingBuildStep.acquireLocks(step, res)
self.assertTrue(b.currentStep is step)
b.stopBuild('stop it')
return retval
step.acquireLocks = acquireLocks
b.startBuild(FakeBuildStatus(), self.workerforbuilder)
self.assertEqual(gotLocks, [True])
self.assertEqual(b.results, CANCELLED)
示例2: testStopBuildWaitingForLocks
def testStopBuildWaitingForLocks(self):
b = self.build
lock = WorkerLock('lock')
lock_access = lock.access('counting')
lock.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(lock) \
.getLock(self.workerforbuilder.worker)
b.setLocks([lock_access])
step = FakeBuildStep()
step.alwaysRun = False
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), lock.access('counting'))
def acquireLocks(res=None):
retval = Build.acquireLocks(b, res)
b.stopBuild('stop it')
return retval
b.acquireLocks = acquireLocks
b.startBuild(FakeBuildStatus(), self.workerforbuilder)
self.assertTrue(b.currentStep is None)
self.assertEqual(b.results, CANCELLED)
示例3: testStopBuildWaitingForLocks_lostRemote
def testStopBuildWaitingForLocks_lostRemote(self):
b = self.build
lock = WorkerLock('lock')
lock_access = lock.access('counting')
lock.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(lock) \
.getLock(self.workerforbuilder.worker)
b.setLocks([lock_access])
step = FakeBuildStep()
step.alwaysRun = False
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), lock.access('counting'))
def acquireLocks(res=None):
retval = Build.acquireLocks(b, res)
b.lostRemote()
return retval
b.acquireLocks = acquireLocks
b.startBuild(FakeBuildStatus(), self.workerforbuilder)
self.assertTrue(b.currentStep is None)
self.assertEqual(b.results, RETRY)
self.build.build_status.setText.assert_called_with(
["retry", "lost", "connection"])
self.build.build_status.setResults.assert_called_with(RETRY)
示例4: testBuildWaitingForLocks
def testBuildWaitingForLocks(self):
b = self.build
l = WorkerLock('lock')
claimCount = [0]
lock_access = l.access('counting')
l.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(l) \
.getLock(self.workerforbuilder.worker)
def claim(owner, access):
claimCount[0] += 1
return real_lock.old_claim(owner, access)
real_lock.old_claim = real_lock.claim
real_lock.claim = claim
b.setLocks([lock_access])
step = Mock()
step.return_value = step
step.startStep.return_value = SUCCESS
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), l.access('counting'))
b.startBuild(FakeBuildStatus(), None, self.workerforbuilder)
self.assert_(('startStep', (self.workerforbuilder.worker.conn,), {})
not in step.method_calls)
self.assertEquals(claimCount[0], 1)
self.assert_(b.currentStep is None)
self.assert_(b._acquiringLock is not None)
示例5: testBuildWaitingForLocks
def testBuildWaitingForLocks(self):
b = self.build
lock = WorkerLock('lock')
claimCount = [0]
lock_access = lock.access('counting')
lock.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(lock) \
.getLock(self.workerforbuilder.worker)
def claim(owner, access):
claimCount[0] += 1
return real_lock.old_claim(owner, access)
real_lock.old_claim = real_lock.claim
real_lock.claim = claim
b.setLocks([lock_access])
step = FakeBuildStep()
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), lock.access('counting'))
b.startBuild(FakeBuildStatus(), self.workerforbuilder)
self.assertEqual(claimCount[0], 1)
self.assertTrue(b.currentStep is None)
self.assertTrue(b._acquiringLock is not None)
示例6: testStopBuildWaitingForLocks_lostRemote
def testStopBuildWaitingForLocks_lostRemote(self):
b = self.build
l = WorkerLock('lock')
lock_access = l.access('counting')
l.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(l) \
.getLock(self.workerforbuilder.worker)
b.setLocks([lock_access])
step = Mock()
step.return_value = step
step.startStep.return_value = SUCCESS
step.alwaysRun = False
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), l.access('counting'))
def acquireLocks(res=None):
retval = Build.acquireLocks(b, res)
b.lostRemote()
return retval
b.acquireLocks = acquireLocks
b.startBuild(FakeBuildStatus(), None, self.workerforbuilder)
self.assert_(('startStep', (self.workerforbuilder.worker.conn,), {})
not in step.method_calls)
self.assert_(b.currentStep is None)
self.assertEqual(b.results, RETRY)
self.assert_(('interrupt', ('stop it',), {}) not in step.method_calls)
self.build.build_status.setText.assert_called_with(["retry", "lost", "connection"])
self.build.build_status.setResults.assert_called_with(RETRY)
示例7: testBuildcanStartWithWorkerForBuilder
def testBuildcanStartWithWorkerForBuilder(self):
b = self.build
workerforbuilder1 = Mock()
workerforbuilder2 = Mock()
l = WorkerLock('lock')
counting_access = l.access('counting')
real_lock = b.builder.botmaster.getLockByID(l)
# no locks, so both these pass (call twice to verify there's no state/memory)
lock_list = [(real_lock, counting_access)]
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
worker_lock_1 = real_lock.getLock(workerforbuilder1.worker)
worker_lock_2 = real_lock.getLock(workerforbuilder2.worker)
# then have workerforbuilder2 claim its lock:
worker_lock_2.claim(workerforbuilder2, counting_access)
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
worker_lock_2.release(workerforbuilder2, counting_access)
# then have workerforbuilder1 claim its lock:
worker_lock_1.claim(workerforbuilder1, counting_access)
self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
self.assertFalse(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder1))
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
self.assertTrue(Build.canStartWithWorkerForBuilder(lock_list, workerforbuilder2))
worker_lock_1.release(workerforbuilder1, counting_access)
示例8: testStopBuildWaitingForLocks
def testStopBuildWaitingForLocks(self):
b = self.build
l = WorkerLock('lock')
lock_access = l.access('counting')
l.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(l) \
.getLock(self.workerforbuilder.worker)
b.setLocks([lock_access])
step = Mock()
step.return_value = step
step.startStep.return_value = SUCCESS
step.alwaysRun = False
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), l.access('counting'))
def acquireLocks(res=None):
retval = Build.acquireLocks(b, res)
b.stopBuild('stop it')
return retval
b.acquireLocks = acquireLocks
b.startBuild(FakeBuildStatus(), self.workerforbuilder)
self.assertNotIn(('startStep', (self.workerforbuilder.worker.conn,), {}),
step.method_calls)
self.assertTrue(b.currentStep is None)
self.assertEqual(b.results, CANCELLED)
self.assertNotIn(('interrupt', ('stop it',), {}), step.method_calls)
示例9: testBuildLocksAcquired
def testBuildLocksAcquired(self):
b = self.build
l = WorkerLock('lock')
claimCount = [0]
lock_access = l.access('counting')
l.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(l) \
.getLock(self.workerforbuilder.worker)
def claim(owner, access):
claimCount[0] += 1
return real_lock.old_claim(owner, access)
real_lock.old_claim = real_lock.claim
real_lock.claim = claim
b.setLocks([lock_access])
step = Mock()
step.return_value = step
step.startStep.return_value = SUCCESS
b.setStepFactories([FakeStepFactory(step)])
b.startBuild(FakeBuildStatus(), self.workerforbuilder)
self.assertEqual(b.results, SUCCESS)
self.assertIn(('startStep', (self.workerforbuilder.worker.conn,), {}),
step.method_calls)
self.assertEquals(claimCount[0], 1)
示例10: testStopBuildWaitingForLocks
def testStopBuildWaitingForLocks(self):
b = self.build
l = WorkerLock("lock")
lock_access = l.access("counting")
l.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(l).getLock(self.workerbuilder.worker)
b.setLocks([lock_access])
step = Mock()
step.return_value = step
step.startStep.return_value = SUCCESS
step.alwaysRun = False
b.setStepFactories([FakeStepFactory(step)])
real_lock.claim(Mock(), l.access("counting"))
def acquireLocks(res=None):
retval = Build.acquireLocks(b, res)
b.stopBuild("stop it")
return retval
b.acquireLocks = acquireLocks
b.startBuild(FakeBuildStatus(), None, self.workerbuilder)
self.assert_(("startStep", (self.workerbuilder.worker.conn,), {}) not in step.method_calls)
self.assert_(b.currentStep is None)
self.assertEqual(b.results, CANCELLED)
self.assert_(("interrupt", ("stop it",), {}) not in step.method_calls)
示例11: testBuildLocksOrder
def testBuildLocksOrder(self):
"""Test that locks are acquired in FIFO order; specifically that
counting locks cannot jump ahead of exclusive locks"""
eBuild = self.build
cBuilder = FakeBuilder(self.master)
cBuild = Build([self.request])
cBuild.setBuilder(cBuilder)
eWorker = Mock()
cWorker = Mock()
eWorker.worker = self.worker
cWorker.worker = self.worker
eWorker.prepare = cWorker.prepare = lambda _: True
eWorker.ping = cWorker.ping = lambda: True
l = WorkerLock("lock", 2)
claimLog = []
realLock = self.master.botmaster.getLockByID(l).getLock(self.worker)
def claim(owner, access):
claimLog.append(owner)
return realLock.oldClaim(owner, access)
realLock.oldClaim = realLock.claim
realLock.claim = claim
eBuild.setLocks([l.access("exclusive")])
cBuild.setLocks([l.access("counting")])
fakeBuild = Mock()
fakeBuildAccess = l.access("counting")
realLock.claim(fakeBuild, fakeBuildAccess)
step = Mock()
step.return_value = step
step.startStep.return_value = SUCCESS
eBuild.setStepFactories([FakeStepFactory(step)])
cBuild.setStepFactories([FakeStepFactory(step)])
e = eBuild.startBuild(FakeBuildStatus(), eWorker)
c = cBuild.startBuild(FakeBuildStatus(), cWorker)
d = defer.DeferredList([e, c])
realLock.release(fakeBuild, fakeBuildAccess)
def check(ign):
self.assertEqual(eBuild.results, SUCCESS)
self.assertEqual(cBuild.results, SUCCESS)
self.assertEqual(claimLog, [fakeBuild, eBuild, cBuild])
d.addCallback(check)
return d
示例12: testBuildLocksAcquired
def testBuildLocksAcquired(self):
b = self.build
lock = WorkerLock('lock')
claimCount = [0]
lock_access = lock.access('counting')
lock.access = lambda mode: lock_access
real_lock = b.builder.botmaster.getLockByID(lock) \
.getLock(self.workerforbuilder.worker)
def claim(owner, access):
claimCount[0] += 1
return real_lock.old_claim(owner, access)
real_lock.old_claim = real_lock.claim
real_lock.claim = claim
b.setLocks([lock_access])
step = FakeBuildStep()
b.setStepFactories([FakeStepFactory(step)])
b.startBuild(FakeBuildStatus(), self.workerforbuilder)
self.assertEqual(b.results, SUCCESS)
self.assertEqual(claimCount[0], 1)