def test_insert_one(self): def reset(collection): collection.drop() def insert_one(collection, _): collection.insert_one({}) def test(collection): self.assertEqual(NTHREADS, collection.count()) lazy_client_trial(reset, insert_one, test, self._get_client)
def test_delete_one(self): def reset(collection): collection.drop() collection.insert_many([{'i': i} for i in range(NTHREADS)]) def delete_one(collection, i): collection.delete_one({'i': i}) def test(collection): self.assertEqual(0, collection.count()) lazy_client_trial(reset, delete_one, test, self._get_client)
def test_update_one(self): def reset(collection): collection.drop() collection.insert_one({'i': 0}) # Update doc 10 times. def update_one(collection, _): collection.update_one({}, {'$inc': {'i': 1}}) def test(collection): self.assertEqual(NTHREADS, collection.find_one()['i']) lazy_client_trial(reset, update_one, test, self._get_client)
def test_insert(self): def reset(collection): collection.drop() def insert(collection, dummy): collection.insert({}) def test(collection): self.assertEqual(NTHREADS, collection.count()) lazy_client_trial( reset, insert, test, self._get_client, use_greenlets=False)
def test_connect(self): def reset(dummy): pass def connect(collection, dummy): self.assertRaises(AutoReconnect, collection.find_one) def test(collection): client = collection.database.connection self.assertEqual(0, len(client.nodes)) lazy_client_trial( reset, connect, test, self._get_client, use_greenlets=False)
def test_find_one(self): results = [] def reset(collection): collection.drop() collection.insert_one({}) results[:] = [] def find_one(collection, _): results.append(collection.find_one()) def test(collection): self.assertEqual(NTHREADS, len(results)) lazy_client_trial(reset, find_one, test, self._get_client)