Kiwi icon indicating copy to clipboard operation
Kiwi copied to clipboard

Replace Testing.individual_test_case_health() with TestExecution.filter() API

Open atodorov opened this issue 4 years ago • 1 comments

Once the individual TestCase Health telemetry is complete research if we really need the Testing.individual_test_case_health method or if that can be replaces with the existing TestExecution.filter. Both are similar but not identical.

While TestExecution.filter() could be extended to return more of the fields needed by telemetry what are the negative effects from doing so?

atodorov avatar Sep 20 '21 15:09 atodorov

potential issue could be that the query from Testing.individual_test_case_health executes a join to get run__plan and status__name. that is slow, and we don't need that data every time.

what we could do is extend the TestExecution.filter API to accept 2 additional parameters - order_by and values and it will look something like this:

@permissions_required("testruns.view_testexecution")
@rpc_method(name="TestExecution.filter")
def filter(query, additional_values=None, order_by=None):  # pylint: disable=redefined-builtin
    """
    .. function:: RPC TestExecution.filter(query)

        Perform a search and return the resulting list of test case executions.

        :param query: Field lookups for :class:`tcms.testruns.models.TestExecution`
        :type query: dict
        :return: List of serialized :class:`tcms.testruns.models.TestExecution` objects
        :rtype: list(dict)
    """
    if additional_values is None:
        additional_values = []
    r = TestExecution.objects.filter(**query)
        .values(
            "id",
            "assignee",
            "assignee__username",
            "tested_by",
            "tested_by__username",
            "case_text_version",
            "start_date",
            "stop_date",
            "sortkey",
            "run",
            "case",
            "case__summary",
            "build",
            "build__name",
            "status",
            "status__name",
            *values
        )
    if order_by is not None:
        r = r.order_by(*order_by)
    return r.distinct()

that way the consumer can control the DB queries. low-level API, but it will do the work in both cases, without much additional overhead.

asankov avatar Sep 20 '21 20:09 asankov