Пример #1
0
def _log_timer_duration_seconds():
    '''
    How long should we wait before logging reports about long-held locks?
    '''
    test_vars = p4gf_util.test_vars()
    if p4gf_const.P4GF_TEST_LOCK_LOG_AFTER_HELD_SECONDS in test_vars:
        return float(test_vars[p4gf_const.P4GF_TEST_LOCK_LOG_AFTER_HELD_SECONDS])
    return float(5 * 60)
Пример #2
0
def _log_timer_duration_seconds():
    '''
    How long should we wait before logging reports about long-held locks?
    '''
    test_vars = p4gf_util.test_vars()
    if p4gf_const.P4GF_TEST_LOCK_LOG_AFTER_HELD_SECONDS in test_vars:
        return float(
            test_vars[p4gf_const.P4GF_TEST_LOCK_LOG_AFTER_HELD_SECONDS])
    return float(5 * 60)
Пример #3
0
    def _test_view_sleep_after(self, key):
        '''
        Some testing code needs us to   s l o w   d o w n
        so that the test can notice the counter change or
        introduce some state change.
        '''
        test_vars = p4gf_util.test_vars()
        if not key in test_vars:
            return

        sleep_seconds = test_vars[key]
        LOG.debug("Test: sleeping {} seconds...".format(sleep_seconds))
        time.sleep(float(sleep_seconds))
        LOG.debug("Test: sleeping {} seconds done".format(sleep_seconds))
Пример #4
0
    def _test_view_sleep_after(self, key):
        '''
        Some testing code needs us to   s l o w   d o w n
        so that the test can notice the counter change or
        introduce some state change.
        '''
        test_vars = p4gf_util.test_vars()
        if not key in test_vars:
            return

        sleep_seconds = test_vars[key]
        LOG.debug("Test: sleeping {} seconds...".format(sleep_seconds))
        time.sleep(float(sleep_seconds))
        LOG.debug("Test: sleeping {} seconds done".format(sleep_seconds))
Пример #5
0
    def test_block_push(self):
        """Test hook to temporarily block and let test script
        introduce conflicting changes.
        """
        s = p4gf_util.test_vars().get(p4gf_const.P4GF_TEST_BLOCK_PUSH)
        if not s:
            return

        log = logging.getLogger("test_block_push")
        block_dict = p4gf_util.test_var_to_dict(s)
        log.debug(block_dict)

        # Fetch ALL the submitted changelists as of right now.
        log.debug("p4 changes {}".format(
            p4gf_path.slash_dot_dot_dot(self.ctx.config.p4client)))
        cl_ay = self.ctx.p4.run(
            'changes', '-l',
            p4gf_path.slash_dot_dot_dot(self.ctx.config.p4client))

        # Don't block until after something?
        after = block_dict['after']
        if after:
            if not contains_desc(after, cl_ay):
                log.debug("Do not block until after: {}".format(after))
                return

        until = block_dict['until']
        log.debug("BLOCKING. Seen        'after': {}".format(after))
        log.debug("BLOCKING. Waiting for 'until': {}".format(until))

        changes_path_at = ("{path}@{change},now".format(
            path=p4gf_path.slash_dot_dot_dot(self.ctx.config.p4client),
            change=cl_ay[-1]['change']))

        while not contains_desc(until, cl_ay):
            time.sleep(1)
            cl_ay = self.ctx.p4.run('changes', changes_path_at)

        log.debug("Block released")
    def test_block_push(self):
        """Test hook to temporarily block and let test script
        introduce conflicting changes.
        """
        s = p4gf_util.test_vars().get(p4gf_const.P4GF_TEST_BLOCK_PUSH)
        if not s:
            return

        log = logging.getLogger("test_block_push")
        block_dict = p4gf_util.test_var_to_dict(s)
        log.debug(block_dict)

        # Fetch ALL the submitted changelists as of right now.
        log.debug("p4 changes {}".format(p4gf_path.slash_dot_dot_dot(self.ctx.config.p4client)))
        cl_ay = self.ctx.p4.run('changes',
                                '-l',
                                p4gf_path.slash_dot_dot_dot(self.ctx.config.p4client))

        # Don't block until after something?
        after = block_dict['after']
        if after:
            if not contains_desc(after, cl_ay):
                log.debug("Do not block until after: {}".format(after))
                return

        until = block_dict['until']
        log.debug("BLOCKING. Seen        'after': {}".format(after))
        log.debug("BLOCKING. Waiting for 'until': {}".format(until))

        changes_path_at = ("{path}@{change},now"
                           .format(path=p4gf_path.slash_dot_dot_dot(self.ctx.config.p4client),
                                   change=cl_ay[-1]['change']))

        while not contains_desc(until, cl_ay):
            time.sleep(1)
            cl_ay = self.ctx.p4.run('changes', changes_path_at)

        log.debug("Block released")
    def heartbeat(self):
        '''
        If we have a view lock, update its heartbeat.

        If our lock is cleared, then raise a RuntimeException
        canceling our current task.
        '''
        if not self.view_lock:
            return

        if self.view_lock.canceled():
            raise RuntimeError("Canceling: lock {} lost."
                               .format(self.view_lock.counter_name()))

        self.view_lock.update_heartbeat()

        # For some of the tests, slow down the operation by sleeping briefly.
        key = p4gf_const.P4GF_TEST_LOCK_VIEW_SLEEP_AFTER_HEARTBEAT_SECONDS
        test_vars = p4gf_util.test_vars()
        if key in test_vars:
            sleep_seconds = test_vars[key]
            LOG.debug("Test: sleeping {} seconds...".format(sleep_seconds))
            time.sleep(float(sleep_seconds))
            LOG.debug("Test: sleeping {} seconds done".format(sleep_seconds))