def test(self): # We'll use fractions to avoid rounding errors. Remember that not every fraction can be # represented as a floating point number. F = Fraction # This test isn't general enough to cover every possible value of minCores in # SingleMachineBatchSystem. Instead we hard-code a value and assert it. minCores = F(1, 10) self.assertEquals(float(minCores), SingleMachineBatchSystem.minCores) for maxCores in {F(minCores), minCores * 10, F(1), F(numCores, 2), F(numCores)}: for coresPerJob in {F(minCores), F(minCores * 10), F(1), F(maxCores, 2), F(maxCores)}: for load in (F(1, 10), F(1), F(10)): jobs = int(maxCores / coresPerJob * load) if jobs >= 1 and minCores <= coresPerJob < maxCores: self.assertEquals(maxCores, float(maxCores)) bs = SingleMachineBatchSystem( config=hidden.AbstractBatchSystemTest.createConfig(), maxCores=float(maxCores), # Ensure that memory or disk requirements don't get in the way. maxMemory=jobs * 10, maxDisk=jobs * 10) try: jobIds = set() for i in range(0, int(jobs)): jobIds.add(bs.issueBatchJob(JobNode(command=self.scriptCommand(), requirements=dict( cores=float( coresPerJob), memory=1, disk=1, preemptable=preemptable), jobName=str(i), unitName='', jobStoreID=str(i)))) self.assertEquals(len(jobIds), jobs) while jobIds: job = bs.getUpdatedBatchJob(maxWait=10) self.assertIsNotNone(job) jobId, status, wallTime = job self.assertEquals(status, 0) # would raise KeyError on absence jobIds.remove(jobId) finally: bs.shutdown() concurrentTasks, maxConcurrentTasks = getCounters(self.counterPath) self.assertEquals(concurrentTasks, 0) log.info('maxCores: {maxCores}, ' 'coresPerJob: {coresPerJob}, ' 'load: {load}'.format(**locals())) # This is the key assertion: expectedMaxConcurrentTasks = min(old_div(maxCores, coresPerJob), jobs) self.assertEquals(maxConcurrentTasks, expectedMaxConcurrentTasks) resetCounters(self.counterPath)
def createBatchSystem(self): return SingleMachineBatchSystem(config=self.config, maxCores=numCores, maxMemory=1e9, maxDisk=2001)
def __init__(self, config: Config, maxCores: float, maxMemory: int, maxDisk: int) -> None: super().__init__(config, maxCores, maxMemory, maxDisk) self.localBatch: SingleMachineBatchSystem = SingleMachineBatchSystem( config, config.maxLocalJobs, maxMemory, maxDisk)