def test_auto_batcher_multi_threaded(self):
        id_set = set()
        id_list = list()

        batch_size = 100

        auto_batcher = _AutoBatcher(batch_size, 0, self._id_batch_supplier)

        def func():
            for i in range(NUM_IDS_IN_THREADS):
                fake_id = auto_batcher.new_id().result()
                id_set.add(fake_id)
                id_list.append(fake_id)

        threads = [threading.Thread(target=func) for _ in range(NUM_THREADS)]

        for t in threads:
            t.start()

        for t in threads:
            t.join()

        # We are faking with this batch size and supplier supplies the same base and increment each
        # time. So, we should see unique ids as many as the batch size
        self.assertEqual(batch_size, len(id_set))

        # We should generate this many ids whether or not they are unique
        self.assertEqual(NUM_THREADS * NUM_IDS_IN_THREADS, len(id_list))
    def test_auto_batcher(self):
        auto_batcher = _AutoBatcher(10, 0, self._id_batch_supplier)

        self.assertEqual(AUTO_BATCHER_BASE, auto_batcher.new_id().result())
        self.assertEqual(AUTO_BATCHER_BASE + FLAKE_ID_STEP,
                         auto_batcher.new_id().result())