Example #1
0
def test_for_empty_search_query(transactional_db, sample_bugs, search_term, exp_bugs):
    """
    Check Bugscache search strings aren't empty when we query with them

    This catches a bug introduced as part of the fix for Bug 1469777.
    """
    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)

    def get_search_query(sql):
        search_query, _, _ = sql.partition('\\"\' IN BOOLEAN MODE')
        _, _, search_query = search_query.partition('AGAINST (\'\\"')

        search_query = search_query.strip(' ')
        return search_query

    with CaptureQueriesContext(connection) as context:
        Bugscache.search(search_term)

        search_query = get_search_query(context.captured_queries[0]['sql'])
        assert search_query

        search_query = get_search_query(context.captured_queries[-1]['sql'])
        assert search_query
Example #2
0
def bug_suggestions_line(err, term_cache=None):
    if term_cache is None:
        term_cache = {}
    # remove the mozharness prefix
    clean_line = get_mozharness_substring(err.line)
    search_terms = []
    # get a meaningful search term out of the error line
    search_term = get_error_search_term(clean_line)
    bugs = dict(open_recent=[], all_others=[])

    # collect open recent and all other bugs suggestions
    if search_term:
        search_terms.append(search_term)
        if search_term not in term_cache:
            term_cache[search_term] = Bugscache.search(search_term)
        bugs = term_cache[search_term]

    if not bugs or not (bugs['open_recent'] or bugs['all_others']):
        # no suggestions, try to use
        # the crash signature as search term
        crash_signature = get_crash_signature(clean_line)
        if crash_signature:
            search_terms.append(crash_signature)
            if crash_signature not in term_cache:
                term_cache[crash_signature] = Bugscache.search(crash_signature)
            bugs = term_cache[crash_signature]

    # TODO: Rename 'search' to 'error_text' or similar, since that's
    # closer to what it actually represents (bug 1091060).
    return {
        "search": clean_line,
        "search_terms": search_terms,
        "bugs": bugs,
    }
Example #3
0
def bug_suggestions_line(err, term_cache=None):
    if term_cache is None:
        term_cache = {}
    # remove the mozharness prefix
    clean_line = get_mozharness_substring(err.line)
    search_terms = []
    # get a meaningful search term out of the error line
    search_term = get_error_search_term(clean_line)
    bugs = dict(open_recent=[], all_others=[])

    # collect open recent and all other bugs suggestions
    if search_term:
        search_terms.append(search_term)
        if search_term not in term_cache:
            term_cache[search_term] = Bugscache.search(search_term)
        bugs = term_cache[search_term]

    if not bugs or not (bugs['open_recent'] or
                        bugs['all_others']):
        # no suggestions, try to use
        # the crash signature as search term
        crash_signature = get_crash_signature(clean_line)
        if crash_signature:
            search_terms.append(crash_signature)
            if crash_signature not in term_cache:
                term_cache[crash_signature] = Bugscache.search(crash_signature)
            bugs = term_cache[crash_signature]

    # TODO: Rename 'search' to 'error_text' or similar, since that's
    # closer to what it actually represents (bug 1091060).
    return {
        "search": clean_line,
        "search_terms": search_terms,
        "bugs": bugs,
    }
Example #4
0
def test_for_empty_search_query(transactional_db, sample_bugs, search_term,
                                exp_bugs):
    """
    Check Bugscache search strings aren't empty when we query with them

    This catches a bug introduced as part of the fix for Bug 1469777.
    """
    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)

    def get_search_query(sql):
        search_query, _, _ = sql.partition('\\"\' IN BOOLEAN MODE')
        _, _, search_query = search_query.partition('AGAINST (\'\\"')

        search_query = search_query.strip(' ')
        return search_query

    with CaptureQueriesContext(connection) as context:
        Bugscache.search(search_term)

        search_query = get_search_query(context.captured_queries[0]['sql'])
        assert search_query

        search_query = get_search_query(context.captured_queries[-1]['sql'])
        assert search_query
Example #5
0
def bug_suggestions_line(err, term_cache=None):
    """
    Get Bug suggestions for a given TextLogError (err).

    Tries to extract a search term from a clean version of the given error's
    line.  We build a search term from the cleaned line and use that to search
    for bugs.  Returns a dictionary with the cleaned line, the generated search
    term, and any bugs found with said search term.
    """
    if term_cache is None:
        term_cache = {}

    # remove the mozharness prefix
    clean_line = get_cleaned_line(err.line)

    # get a meaningful search term out of the error line
    search_info = get_error_search_term_and_path(clean_line)
    search_term = search_info["search_term"]
    path_end = search_info["path_end"]
    bugs = dict(open_recent=[], all_others=[])

    # collect open recent and all other bugs suggestions
    search_terms = []
    if search_term:
        search_terms.append(search_term)
        if search_term not in term_cache:
            term_cache[search_term] = Bugscache.search(search_term)
        bugs = term_cache[search_term]

    if not bugs or not (bugs['open_recent'] or bugs['all_others']):
        # no suggestions, try to use
        # the crash signature as search term
        crash_signature = get_crash_signature(clean_line)
        if crash_signature:
            search_terms.append(crash_signature)
            if crash_signature not in term_cache:
                term_cache[crash_signature] = Bugscache.search(crash_signature)
            bugs = term_cache[crash_signature]

    # TODO: Rename 'search' to 'error_text' or similar, since that's
    # closer to what it actually represents (bug 1091060).
    return {
        "search": clean_line,
        "search_terms": search_terms,
        "path_end": path_end,
        "bugs": bugs,
        "line_number": err.line_number,
    }
Example #6
0
def get_error_summary(all_errors):
    """
    Transform the error lines into the artifact format.

    Add bug suggestions if they are found.
    """
    error_summary = []
    terms_requested = {}

    for err in all_errors:
        # remove the mozharness prefix
        clean_line = get_mozharness_substring(err['line'])
        search_terms = []
        # get a meaningful search term out of the error line
        search_term = get_error_search_term(clean_line)
        bugs = dict(open_recent=[], all_others=[])

        # collect open recent and all other bugs suggestions
        if search_term:
            search_terms.append(search_term)
            if search_term not in terms_requested:
                bugs = Bugscache.search(search_term)
                terms_requested[search_term] = bugs
            else:
                bugs = terms_requested[search_term]

        if not bugs or not (bugs['open_recent'] or
                            bugs['all_others']):
            # no suggestions, try to use
            # the crash signature as search term
            crash_signature = get_crash_signature(clean_line)
            if crash_signature:
                search_terms.append(crash_signature)
                if crash_signature not in terms_requested:
                    bugs = Bugscache.search(crash_signature)
                    terms_requested[crash_signature] = bugs
                else:
                    bugs = terms_requested[crash_signature]

        # TODO: Rename 'search' to 'error_text' or similar, since that's
        # closer to what it actually represents (bug 1091060).
        error_summary.append({
            "search": clean_line,
            "search_terms": search_terms,
            "bugs": bugs
        })

    return error_summary
Example #7
0
def get_error_summary(all_errors):
    """
    Transform the error lines into the artifact format.

    Add bug suggestions if they are found.
    """
    error_summary = []
    terms_requested = {}

    for err in all_errors:
        # remove the mozharness prefix
        clean_line = get_mozharness_substring(err['line'])
        search_terms = []
        # get a meaningful search term out of the error line
        search_term = get_error_search_term(clean_line)
        bugs = dict(open_recent=[], all_others=[])

        # collect open recent and all other bugs suggestions
        if search_term:
            search_terms.append(search_term)
            if search_term not in terms_requested:
                bugs = Bugscache.search(search_term)
                terms_requested[search_term] = bugs
            else:
                bugs = terms_requested[search_term]

        if not bugs or not (bugs['open_recent'] or bugs['all_others']):
            # no suggestions, try to use
            # the crash signature as search term
            crash_signature = get_crash_signature(clean_line)
            if crash_signature:
                search_terms.append(crash_signature)
                if crash_signature not in terms_requested:
                    bugs = Bugscache.search(crash_signature)
                    terms_requested[crash_signature] = bugs
                else:
                    bugs = terms_requested[crash_signature]

        # TODO: Rename 'search' to 'error_text' or similar, since that's
        # closer to what it actually represents (bug 1091060).
        error_summary.append({
            "search": clean_line,
            "search_terms": search_terms,
            "bugs": bugs
        })

    return error_summary
def populate_bugscache():
    return Bugscache.objects.bulk_create([
        Bugscache(
            id=1234567,
            status='NEW',
            summary=
            'intermittent devtools/client/framework/test/test1.js | single tracking bug',
            modified='2014-01-01 00:00:00',
        ),
        Bugscache(
            id=2345678,
            status='NEW',
            summary=
            'intermittent devtools/client/framework/test/test2.js | single tracking bug',
            modified='2014-01-01 00:00:00',
        ),
    ])
Example #9
0
def bug_suggestions_line(err, term_cache=None):
    """
    Get Bug suggestions for a given TextLogError (err).

    Tries to extract a search term from a clean version of the given error's
    line.  We build a search term from the cleaned line and use that to search
    for bugs.  Returns a dictionary with the cleaned line, the generated search
    term, and any bugs found with said search term.
    """
    if term_cache is None:
        term_cache = {}

    # remove the mozharness prefix
    clean_line = get_mozharness_substring(err.line)

    # get a meaningful search term out of the error line
    search_term = get_error_search_term(clean_line)
    bugs = dict(open_recent=[], all_others=[])

    # collect open recent and all other bugs suggestions
    search_terms = []
    if search_term:
        search_terms.append(search_term)
        if search_term not in term_cache:
            term_cache[search_term] = Bugscache.search(search_term)
        bugs = term_cache[search_term]

    if not bugs or not (bugs['open_recent'] or
                        bugs['all_others']):
        # no suggestions, try to use
        # the crash signature as search term
        crash_signature = get_crash_signature(clean_line)
        if crash_signature:
            search_terms.append(crash_signature)
            if crash_signature not in term_cache:
                term_cache[crash_signature] = Bugscache.search(crash_signature)
            bugs = term_cache[crash_signature]

    # TODO: Rename 'search' to 'error_text' or similar, since that's
    # closer to what it actually represents (bug 1091060).
    return {
        "search": clean_line,
        "search_terms": search_terms,
        "bugs": bugs,
    }
Example #10
0
def test_get_open_recent_bugs(transactional_db, sample_bugs, search_term, exp_bugs):
    """Test that we retrieve the expected open recent bugs for a search term."""
    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)
    suggestions = Bugscache.search(search_term)
    open_recent_bugs = [b['id'] for b in suggestions['open_recent']]
    assert open_recent_bugs == exp_bugs
    assert suggestions['all_others'] == []
Example #11
0
def test_get_open_recent_bugs(transactional_db, sample_bugs, search_term,
                              exp_bugs):
    """Test that we retrieve the expected open recent bugs for a search term."""
    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)
    suggestions = Bugscache.search(search_term)
    open_recent_bugs = [b['id'] for b in suggestions['open_recent']]
    assert open_recent_bugs == exp_bugs
    assert suggestions['all_others'] == []
Example #12
0
def test_get_all_other_bugs(transactional_db, sample_bugs, search_term, exp_bugs):
    """Test that we retrieve the expected old bugs for a search term."""
    bug_list = sample_bugs['bugs']
    ninetyfive_days_ago = datetime.now() - timedelta(days=95)
    # Update the last_change date so that all bugs will be placed in
    # the all_others bucket, and none in open_recent.
    for bug in bug_list:
        bug['last_change_time'] = ninetyfive_days_ago
    _update_bugscache(bug_list)

    suggestions = Bugscache.search(search_term)
    assert len(suggestions['open_recent']) == 0
    all_others_bugs = [b['id'] for b in suggestions['all_others']]
    assert all_others_bugs == exp_bugs
def test_get_all_other_bugs(transactional_db, sample_bugs, search_term,
                            exp_bugs):
    """Test that we retrieve the expected old bugs for a search term."""
    bug_list = sample_bugs['bugs']
    ninetyfive_days_ago = datetime.now() - timedelta(days=95)
    # Update the last_change date so that all bugs will be placed in
    # the all_others bucket, and none in open_recent.
    for bug in bug_list:
        bug['last_change_time'] = ninetyfive_days_ago
    _update_bugscache(bug_list)

    suggestions = Bugscache.search(search_term)
    assert len(suggestions['open_recent']) == 0
    all_others_bugs = [b['id'] for b in suggestions['all_others']]
    assert all_others_bugs == exp_bugs
Example #14
0
def test_bug_properties(transactional_db, sample_bugs):
    """Test that we retrieve recent, but fixed bugs for a search term."""
    search_term = "test_popup_preventdefault_chrome.xul"
    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)

    expected_keys = set(['crash_signature', 'resolution', 'summary', 'keywords', 'os', 'id',
                         'status', 'whiteboard'])

    suggestions = Bugscache.search(search_term)
    assert set(suggestions['open_recent'][0].keys()) == expected_keys
Example #15
0
def test_get_recent_resolved_bugs(transactional_db, sample_bugs):
    """Test that we retrieve recent, but fixed bugs for a search term."""
    search_term = "Recently modified resolved bugs should be returned in all_others"
    exp_bugs = [100001]

    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)

    suggestions = Bugscache.search(search_term)
    assert suggestions['open_recent'] == []
    all_others_bugs = [b['id'] for b in suggestions['all_others']]
    assert all_others_bugs == exp_bugs
Example #16
0
def test_get_recent_resolved_bugs(transactional_db, sample_bugs):
    """Test that we retrieve recent, but fixed bugs for a search term."""
    search_term = "Recently modified resolved bugs should be returned in all_others"
    exp_bugs = [100001]

    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)

    suggestions = Bugscache.search(search_term)
    assert suggestions['open_recent'] == []
    all_others_bugs = [b['id'] for b in suggestions['all_others']]
    assert all_others_bugs == exp_bugs
Example #17
0
def test_bug_properties(transactional_db, sample_bugs):
    """Test that we retrieve recent, but fixed bugs for a search term."""
    search_term = "test_popup_preventdefault_chrome.xul"
    bug_list = sample_bugs['bugs']
    fifty_days_ago = datetime.now() - timedelta(days=50)
    # Update the last_change date so that all bugs will be placed in
    # the open_recent bucket, and none in all_others.
    for bug in bug_list:
        bug['last_change_time'] = fifty_days_ago
    _update_bugscache(bug_list)

    expected_keys = set([
        'crash_signature', 'resolution', 'summary', 'keywords', 'os', 'id',
        'status', 'whiteboard'
    ])

    suggestions = Bugscache.search(search_term)
    assert set(suggestions['open_recent'][0].keys()) == expected_keys