'Tests rollback. We force a rollback by adding a doc, killing the
primary, adding another doc, killing the new primary, and then
restarting both.'

def test_rollback(self):

    primary_conn = self.repl_set.primary.client()
    self.conn['test']['test'].insert_one({'name': 'paul'})
    condition = (lambda : (self.conn['test']['test'].find_one({'name': 'paul'}) is not None))
    assert_soon(condition)
    assert_soon((lambda : (sum((1 for _ in self._search())) == 1)))
    self.repl_set.primary.stop(destroy=False)
    new_primary_conn = self.repl_set.secondary.client()
    admin = new_primary_conn['admin']
    condition = (lambda : admin.command('isMaster')['ismaster'])
    assert_soon((lambda : retry_until_ok(condition)))
    retry_until_ok(self.conn.test.test.insert_one, {'name': 'pauline'})
    assert_soon((lambda : (sum((1 for _ in self._search())) == 2)))
    result_set_1 = list(self._search())
    result_set_2 = self.conn['test']['test'].find_one({'name': 'pauline'})
    self.assertEqual(len(result_set_1), 2)
    for item in result_set_1:
        if (item['name'] == 'pauline'):
            self.assertEqual(item['_id'], result_set_2['_id'])
    self.repl_set.secondary.stop(destroy=False)
    self.repl_set.primary.start()
    assert_soon((lambda : primary_conn['admin'].command('isMaster')['ismaster']))
    self.repl_set.secondary.start()
    time.sleep(2)
    result_set_1 = list(self._search())
    self.assertEqual(len(result_set_1), 1)
    for item in result_set_1:
        self.assertEqual(item['name'], 'paul')
    find_cursor = retry_until_ok(self.conn['test']['test'].find)
    self.assertEqual(retry_until_ok(find_cursor.count), 1)
