def _bisect()

in mozregression/bisector.py [0:0]


    def _bisect(self, handler, build_range):
        """
        Starts a bisection for a :class:`mozregression.build_range.BuildData`.
        """

        bisection = Bisection(
            handler,
            build_range,
            self.download_manager,
            self.test_runner,
            dl_in_background=self.dl_in_background,
            approx_chooser=self.approx_chooser,
        )

        previous_verdict = None

        while True:
            index = bisection.search_mid_point()
            result = bisection.init_handler(index)
            if result != bisection.RUNNING:
                return result
            if previous_verdict is None and handler.ensure_good_and_bad:
                if bisection.ensure_good_and_bad():
                    LOG.info("Good and bad builds are correct. Let's" " continue the bisection.")
                else:
                    return bisection.USER_EXIT
            bisection.handler.print_range(full=False)

            if previous_verdict == "back":
                index = bisection.history.pop(-1).index

            allow_bg_download = True
            if previous_verdict == "s":
                # disallow background download since we are not sure of what
                # to download next.
                allow_bg_download = False
                index = self.test_runner.index_to_try_after_skip(bisection.build_range)

            index_promise = None
            build_info = bisection.build_range[index]
            try:
                if previous_verdict != "r" and build_info:
                    # if the last verdict was retry, do not download
                    # the build. Futhermore trying to download if we are
                    # in background download mode would stop the next builds
                    # from downloading.
                    index_promise, build_info = bisection.download_build(
                        index, allow_bg_download=allow_bg_download
                    )

                if not build_info:
                    LOG.info("Unable to find build info. Skipping this build...")
                    verdict = "s"
                else:
                    try:
                        verdict = bisection.evaluate(build_info)
                    except LauncherError as exc:
                        # we got an unrecoverable error while trying
                        # to run the tested app. We can just fallback
                        # to skip the build.
                        LOG.info("Error: %s. Skipping this build..." % exc)
                        verdict = "s"
            finally:
                # be sure to terminate the index_promise thread in all
                # circumstances.
                if index_promise:
                    index = index_promise()
            previous_verdict = verdict
            result = bisection.handle_verdict(index, verdict)
            if result != bisection.RUNNING:
                return result