if qos_enabled:
        db = WithQoS(db, qos_max_tries, qos_wait_time)

    # Arguments.
    args = parse_args()

    # Command runner.
    cmd_runner = CmdRunner()

    # Repository.
    retdec_repo_dir = config['daemon']['retdec_repo_dir']
    if not retdec_repo_dir:
        raise ValueError("'retdec_repo_dir' in [daemon] is not set")
    elif retdec_repo_dir == config['runner']['retdec_repo_dir']:
        raise ValueError('runner and daemon cannot share the same repository')
    repo = Repository(retdec_repo_dir, cmd_runner)
    if qos_enabled:
        repo = WithQoS(repo, qos_max_tries, qos_wait_time)

    commits = []
    wait_time = int(config['daemon']['wait_time'])
    while True:
        repo.update()

        # Get commits to be processed. We simply extend the list and merge any
        # duplicates afterwards.
        #
        # (1) Not-yet-processed commits that are already in the database.
        commits.extend(db.get_unprocessed_commits())
        # (2) New commits in the repository.
        max_initial_commits = int(config['daemon']['max_initial_commits'])
Пример #2
0
    tests_dir = get_tests_dir(args.tests_dir, tests_root_dir)
    excluded_dirs = get_excluded_dirs(tests_root_dir, config)

    # Workers (spawned processes by the multiprocessing module) need access to
    # the test cases, so get them. They need to be stored in a global variable.
    # The main process gets them after a checkout of the appropriate commit
    # from the repository.
    if __name__ != '__main__':
        test_cases = get_test_cases_to_run(tests_dir, tests_root_dir,
                                           excluded_dirs, config, args)

    if __name__ == '__main__':
        # The main process.

        # Repository.
        repo = Repository(config['runner']['retdec_repo_dir'], cmd_runner)
        if qos_enabled:
            repo = WithQoS(repo, qos_max_tries, qos_wait_time)

        # Tested commit.
        if args.commit is not None:
            repo.update()
            tested_commit = repo.get_commit_from_hash(args.commit)
        else:
            tested_commit = repo.get_current_commit()
        db.initialize_commit_records(
            tested_commit,
            # When the user does not want to re-run tests that have already run
            # (i.e. he or she wants to resume the execution), do not remove
            # existing test results and sent emails from the database.
            remove_test_results=not args.resume,
    def test_raises_exception_when_clone_fails(self):
        self.cmd_runner.run_cmd.return_value = ('error', 1, False)

        with self.assertRaisesRegex(GitError, r'.*clone.*'):
            Repository.clone('url', 'path', self.cmd_runner)
    def test_creates_repository_when_clone_succeeds(self):
        self.cmd_runner.run_cmd.return_value = ('', 0, False)

        repo = Repository.clone('url', 'path', self.cmd_runner)

        self.assertEqual(repo.path, os.path.join(os.getcwd(), 'path'))
    def test_calls_correct_git_command(self):
        Repository.clone('url', 'path', self.cmd_runner)

        self.cmd_runner.run_cmd.assert_any_call(
            ['git', 'clone', 'url', 'path']
        )
 def create_repo(self, path):
     return Repository(path, self.cmd_runner)