def testBuildcanStartWithWorkerbuilder(self): b = self.build workerbuilder1 = Mock() workerbuilder2 = 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.canStartWithWorkerbuilder(lock_list, workerbuilder1)) self.assertTrue(Build.canStartWithWorkerbuilder(lock_list, workerbuilder1)) self.assertTrue(Build.canStartWithWorkerbuilder(lock_list, workerbuilder2)) self.assertTrue(Build.canStartWithWorkerbuilder(lock_list, workerbuilder2)) worker_lock_1 = real_lock.getLock(workerbuilder1.worker) worker_lock_2 = real_lock.getLock(workerbuilder2.worker) # then have workerbuilder2 claim its lock: worker_lock_2.claim(workerbuilder2, counting_access) self.assertTrue(Build.canStartWithWorkerbuilder(lock_list, workerbuilder1)) self.assertTrue(Build.canStartWithWorkerbuilder(lock_list, workerbuilder1)) self.assertFalse(Build.canStartWithWorkerbuilder(lock_list, workerbuilder2)) self.assertFalse(Build.canStartWithWorkerbuilder(lock_list, workerbuilder2)) worker_lock_2.release(workerbuilder2, counting_access) # then have workerbuilder1 claim its lock: worker_lock_1.claim(workerbuilder1, counting_access) self.assertFalse(Build.canStartWithWorkerbuilder(lock_list, workerbuilder1)) self.assertFalse(Build.canStartWithWorkerbuilder(lock_list, workerbuilder1)) self.assertTrue(Build.canStartWithWorkerbuilder(lock_list, workerbuilder2)) self.assertTrue(Build.canStartWithWorkerbuilder(lock_list, workerbuilder2)) worker_lock_1.release(workerbuilder1, counting_access)
def canStartWithWorkerbuilder(self, workerbuilder): locks = [(self.botmaster.getLockFromLockAccess(access), access) for access in self.config.locks] return Build.canStartWithWorkerbuilder(locks, workerbuilder)