'Test that Connector can replicate updates successfully.'

def test_update(self):

    doc = {'a': 1, 'b': 2}
    self.conn.test.test.insert_one(doc)
    selector = {'_id': doc['_id']}
    def update_and_retrieve(update_spec, replace=False):
        if replace:
            self.conn.test.test.replace_one(selector, update_spec)
        else:
            self.conn.test.test.update_one(selector, update_spec)
        time.sleep(1)
        return self.synchronizer._search()[0]
    doc = update_and_retrieve({'a': 1, 'b': 2, 'c': 10}, replace=True)
    self.assertEqual(doc['a'], 1)
    self.assertEqual(doc['b'], 2)
    self.assertEqual(doc['c'], 10)
    doc = update_and_retrieve({'$set': {'b': 4}})
    self.assertEqual(doc['a'], 1)
    self.assertEqual(doc['b'], 4)
    doc = update_and_retrieve({'$unset': {'a': True}})
    self.assertNotIn('a', doc)
    self.assertEqual(doc['b'], 4)
    doc = update_and_retrieve({'$unset': {'b': True}, '$set': {'c': 3}})
    self.assertEqual(doc['c'], 3)
    self.assertNotIn('b', doc)
    opthread = self.connector.shard_set[0]
    opthread.namespace_config = NamespaceConfig(include_fields=['a', 'b', 'c'])
    try:
        doc = update_and_retrieve({'$set': {'d': 10}})
        self.assertEqual(self.conn.test.test.find_one(doc['_id'])['d'], 10)
        self.assertNotIn('d', doc)
        doc = update_and_retrieve({'$set': {'a': 10}})
        self.assertEqual(doc['a'], 10)
    finally:
        opthread.fields = None
