def canStartWithWorkerForBuilder(self, workerforbuilder, buildrequests=None): locks = self.config.locks if IRenderable.providedBy(locks): if buildrequests is None: raise RuntimeError("buildrequests parameter must be specified " " when using renderable builder locks. Not " "specifying buildrequests is deprecated") # collect properties that would be set for a build if we # started it now and render locks using it props = Properties() Build.setupPropertiesKnownBeforeBuildStarts( props, buildrequests, self, workerforbuilder) locks = yield props.render(locks) # Make sure we don't warn and throw an exception at the same time if buildrequests is None: warnings.warn("Not passing corresponding buildrequests to " "Builder.canStartWithWorkerForBuilder is deprecated") locks = [(self.botmaster.getLockFromLockAccess(access), access) for access in locks] can_start = Build.canStartWithWorkerForBuilder(locks, workerforbuilder) defer.returnValue(can_start)
def canStartWithWorkerForBuilder(self, workerforbuilder, buildrequests=None): locks = self.config.locks if IRenderable.providedBy(locks): if buildrequests is None: raise RuntimeError("buildrequests parameter must be specified " " when using renderable builder locks. Not " "specifying buildrequests is deprecated") # collect properties that would be set for a build if we # started it now and render locks using it props = Properties() Build.setupPropertiesKnownBeforeBuildStarts(props, buildrequests, self, workerforbuilder) locks = yield props.render(locks) # Make sure we don't warn and throw an exception at the same time if buildrequests is None: warnings.warn( "Not passing corresponding buildrequests to " "Builder.canStartWithWorkerForBuilder is deprecated") locks = [(self.botmaster.getLockFromLockAccess(access), access) for access in locks] can_start = Build.canStartWithWorkerForBuilder(locks, workerforbuilder) defer.returnValue(can_start)
def testBuildcanStartWithWorkerForBuilder(self): b = self.build workerforbuilder1 = Mock() workerforbuilder2 = Mock() lock = WorkerLock('lock') counting_access = lock.access('counting') real_lock = b.builder.botmaster.getLockByID(lock) # 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)
def canStartWithWorkerForBuilder(self, workerforbuilder): locks = [(self.botmaster.getLockFromLockAccess(access), access) for access in self.config.locks] return Build.canStartWithWorkerForBuilder(locks, workerforbuilder)