'Stress test for a rollback with many documents.'

def test_stressed_rollback(self):

    self.opman.start()
    c = self.main_conn.test.mc
    docman = self.opman.doc_managers[0]
    c2 = c.with_options(write_concern=WriteConcern(w=2))
    c2.insert_many([{'i': i} for i in range(STRESS_COUNT)])
    assert_soon((lambda : (c2.count() == STRESS_COUNT)))
    condition = (lambda : (len(docman._search()) == STRESS_COUNT))
    assert_soon(condition, ('Was    expecting    %d    documents    in    DocManager,    but    %d    found    instead.' % (STRESS_COUNT, len(docman._search()))))
    primary_conn = self.repl_set.primary.client()
    self.repl_set.primary.stop(destroy=False)
    new_primary_conn = self.repl_set.secondary.client()
    admin = new_primary_conn.admin
    assert_soon((lambda : retry_until_ok(admin.command, 'isMaster')['ismaster']))
    retry_until_ok(c.insert_many, [{'i': str((STRESS_COUNT + i))} for i in range(STRESS_COUNT)])
    self.repl_set.secondary.stop(destroy=False)
    self.repl_set.primary.start()
    admin = primary_conn.admin
    assert_soon((lambda : retry_until_ok(admin.command, 'isMaster')['ismaster']))
    self.repl_set.secondary.start()
    assert_soon((lambda : (retry_until_ok(c.count) == STRESS_COUNT)))
    assert_soon(condition, ('Was    expecting    %d    documents    in    DocManager,    but    %d    found    instead.' % (STRESS_COUNT, len(docman._search()))))
    self.opman.join()
