'Test that DocManagers have proper state after both a successful
and an unsuccessful chunk migration'

def test_with_chunk_migration(self):

    self.opman1.start()
    self.opman2.start()
    collection = self.mongos_conn['test']['mcsharded']
    for i in range(1000):
        collection.insert_one({'i': (i + 500)})
    self.assertEqual(self.shard1_conn['test']['mcsharded'].find().count(), 500)
    self.assertEqual(self.shard2_conn['test']['mcsharded'].find().count(), 500)
    assert_soon((lambda : (len(self.opman1.doc_managers[0]._search()) == 1000)))
    self.mongos_conn['admin'].command('moveChunk', 'test.mcsharded', find={'i': 1}, to='demo-set-1')
    all_docs = self.opman1.doc_managers[0]._search()
    self.assertEqual(len(all_docs), 1000)
    for (i, doc) in enumerate(sorted(all_docs, key=(lambda x: x['i']))):
        self.assertEqual(doc['i'], (i + 500))
    self.mongos_conn['config']['collections'].update_one({'_id': 'test.mcsharded'}, {'$set': {'dropped': True}})
    def fail_to_move_chunk():
        self.mongos_conn['admin'].command('moveChunk', 'test.mcsharded', find={'i': 1}, to='demo-set-0')
    self.assertRaises(pymongo.errors.OperationFailure, fail_to_move_chunk)
    all_docs = self.opman1.doc_managers[0]._search()
    self.assertEqual(len(all_docs), 1000)
    for (i, doc) in enumerate(sorted(all_docs, key=(lambda x: x['i']))):
        self.assertEqual(doc['i'], (i + 500))
