Beispiel #1
0
    def test_wait_absent(self):

        for wait_time in (
                -1,
                0.0,
                0.1,
                1,
        ):

            dd('no node wait:', wait_time)

            with ututil.Timer() as t:
                zkutil.wait_absent(self.zk, 'a', wait_time)
                self.assertAlmostEqual(0, t.spent(), delta=0.2)
Beispiel #2
0
    def wait_tx_to_finish(self, txid, timeout):

        logger.info('{tx} wait-> {other_txid}'.format(tx=self, other_txid=txidstr(txid)))

        try:
            zkutil.wait_absent(self.zke,
                               self.zke._zkconf.tx_alive(txid),
                               timeout=timeout)
        except zkutil.ZKWaitTimeout as e:

            logger.info(repr(e) + ' while waiting for other tx: {txid}'.format(
                txid=txid))

            raise TXTimeout('{tx} timeout waiting for tx:{txid}'.format(tx=self, txid=txid))
    def wait_tx_to_finish(self, txid, timeout):

        logger.info('{tx} wait-> {other_txid}'.format(tx=self, other_txid=txidstr(txid)))

        try:
            zkutil.wait_absent(self.zke,
                               self.zke._zkconf.tx_alive(txid),
                               timeout=timeout)
        except zkutil.ZKWaitTimeout as e:

            logger.info(repr(e) + ' while waiting for other tx: {txid}'.format(
                txid=txid))

            raise TXTimeout('{tx} timeout waiting for tx:{txid}'.format(tx=self, txid=txid))
    def test_wait_absent(self):

        for wait_time in (
                -1,
                0.0,
                0.1,
                1,
        ):

            dd('no node wait:', wait_time)

            with ututil.Timer() as t:
                zkutil.wait_absent(self.zk, 'a', wait_time)
                self.assertAlmostEqual(0, t.spent(), delta=0.2)
    def test_wait_absent_no_timeout(self):

        def _del():
            time.sleep(1)
            self.zk.delete('a')

        for kwargs in (
            {},
                {'timeout': None},
        ):

            self.zk.create('a')
            th = threadutil.start_daemon(target=_del)

            with ututil.Timer() as t:
                zkutil.wait_absent(self.zk, 'a', **kwargs)
                self.assertAlmostEqual(1, t.spent(), delta=0.1)

            th.join()
Beispiel #6
0
    def test_wait_absent_no_timeout(self):
        def _del():
            time.sleep(1)
            self.zk.delete('a')

        for kwargs in (
            {},
            {
                'timeout': None
            },
        ):

            self.zk.create('a')
            th = threadutil.start_daemon(target=_del)

            with ututil.Timer() as t:
                zkutil.wait_absent(self.zk, 'a', **kwargs)
                self.assertAlmostEqual(1, t.spent(), delta=0.1)

            th.join()
Beispiel #7
0
    def test_wait_absent_delete_node(self):

        delete_after = 0.2

        for wait_time in (
                0.5,
                1,
        ):
            dd('node present wait:', wait_time)

            self.zk.create('a')

            def _del():
                time.sleep(delete_after)
                self.zk.delete('a')

            th = threadutil.start_daemon(target=_del)
            with ututil.Timer() as t:
                zkutil.wait_absent(self.zk, 'a', wait_time)
                self.assertAlmostEqual(delete_after, t.spent(), delta=0.1)

            th.join()
    def test_wait_absent_delete_node(self):

        delete_after = 0.2

        for wait_time in (
                0.5,
                1,
        ):
            dd('node present wait:', wait_time)

            self.zk.create('a')

            def _del():
                time.sleep(delete_after)
                self.zk.delete('a')

            th = threadutil.start_daemon(target=_del)
            with ututil.Timer() as t:
                zkutil.wait_absent(self.zk, 'a', wait_time)
                self.assertAlmostEqual(delete_after, t.spent(), delta=0.1)

            th.join()