@ComputedGraphTestHarness.UnderHarness
    def test_writing_while_disconnected(self):
        currentView = [self.sharedState.newView()]

        cppView1 = CumulusNative.PersistentCacheIndex(
            currentView[0],
            callbackScheduler
            )

        def writeInLoop():
            for ix in range(100):
                time.sleep(0.01)
                cppView1.addPage(sha1("page" + str(ix)),HashSet(), ix, sha1(""))

        thread1 = threading.Thread(target=writeInLoop)
        thread1.start()

        def disconnectAndReconnectInLoop():
            ix = 0
            while thread1.isAlive():
                ix += 1
                time.sleep(0.004)
                currentView[0].disconnect()
                currentView[0] = self.sharedState.newView()
                cppView1.resetView(currentView[0])

        thread2 = threading.Thread(target=disconnectAndReconnectInLoop)
        thread2.start()

        thread1.join()
        thread2.join()

        self.assertTrue(cppView1.timesViewReconnected() > 10)

        cppView2 = CumulusNative.PersistentCacheIndex(
            self.sharedState.newView(),
            callbackScheduler
            )

        time.sleep(2.0)

        count1 = 0
        count2 = 0
        for ix in range(100):
            if cppView1.pageExists(sha1("page" + str(ix))):
                count1 += 1

            if cppView2.pageExists(sha1("page" + str(ix))):
                count2 += 1

        self.assertTrue(count1 == 100 and count2 == 100, (count1, count2))
dataset/ETHPy150Open ufora/ufora/ufora/cumulus/PersistentCache/PersistentCacheIndex_test.py/TestPersistentCacheIndex.test_writing_while_disconnected/original