def test_40_multiple_queues_concurrent(self): queues = [] stacks = {} for i in range(self.queues): queue = Queue("queue_%03d" % i) queue.conn_adapter = ConnAdapter(self._connect()) queues.append(queue) stacks[queue.name] = [] enqueuers = [] lockers = [] for i in range(self.tries): for queue in queues: job = ( '%s_test_method_%03d' % (queue.name, i), '%s_test_args_%03d' % (queue.name, i), ) stacks[queue.name].append(job) enqueuers.append( ConcurrentEnqueue(queue, job)) lockers.append( ConcurrentLock(queue, stacks[queue.name])) while enqueuers: enqueuers_row = enqueuers[:self.max_clients] for enqueuer in enqueuers_row: enqueuer.start() for enqueuer in enqueuers_row: enqueuer.join() enqueuers = enqueuers[self.max_clients:] while lockers: lockers_row = lockers[:self.max_clients] for locker in lockers_row: locker.start() for locker in lockers_row: locker.join() if locker.error: self.fail(locker.error) lockers = lockers[self.max_clients:] for stack in stacks.values(): self.assertEqual(len(stack), 0, "The stacks of jobs should be empty after locked them all")
def test_25_main_queue_multiple_connections(self): queues = [] for i in range(self.queues): queue = Queue(self.queue.name) queue.conn_adapter = ConnAdapter(self._connect()) queues.append(queue) stack = [] for i in range(self.tries): queue = queues[i % len(queues)] job = { 'method' : 'Kernel.puts', 'args' : ["Job %d executed" % i], } queue.enqueue(job['method'], job['args']) stack.append(job) for i in range(self.tries): queue = queues[i % len(queues)] got = self.queue.lock() self.assertIsNotNone(got) try: stack.remove(dict(method=got['method'], args=got['args'])) # NOTE: problems appears if you don't delete the job queue.delete(got['id']) except ValueError: self.fail("can't remove item %s from the stack" % repr(got))
def test_30_multiple_queue_multiple_connections(self): queues = [] for i in range(self.queues): queue = Queue("queue_%03d" % i) queue.conn_adapter = ConnAdapter(self._connect()) queues.append(queue) stack = [] for i in range(self.tries): queue = queues[i % len(queues)] job = ('Kernel.puts', ["Job %d executed" % i]) queue.enqueue(*job) stack.append(job) for i in range(self.tries): queue = queues[i % len(queues)] got = queue.lock() self.assertIsNotNone(got) try: stack.remove((got['method'], got['args'])) # TODO: Problems appears if you don't delete the job queue.delete(got['id']) except ValueError: self.fail("can't remove item %s in stack" % got)