Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve aggregate test results function #813

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 142 additions & 77 deletions graphql_api/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RepositoryFactory,
RepositoryTokenFactory,
)
from reports.tests.factories import TestFactory, TestInstanceFactory
from reports.tests.factories import DailyTestRollupFactory, TestFactory
from services.profiling import CriticalFile

from .helper import GraphQLTestHelper
Expand Down Expand Up @@ -875,9 +875,8 @@ def test_fetch_is_github_rate_limited_but_errors(
def test_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
test=test, created_at=datetime.datetime.now(), repoid=repo.repoid
)

_ = DailyTestRollupFactory(test=test)
res = self.fetch_repository(
repo.name, """testResults { edges { node { name } } }"""
)
Expand All @@ -893,14 +892,15 @@ def test_test_results_no_tests(self) -> None:
def test_branch_filter_on_test_results(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am I missing something or are there no assertions on this test and the next two?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the github file viewer is just not showing them, they are there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh weird, yeah I see them now

repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
test2 = TestFactory(repository=repo)
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
repoid=repo.repoid,
branch="main",
)
_test_instance_2 = TestInstanceFactory(
test=test,
_ = DailyTestRollupFactory(
test=test2,
created_at=datetime.datetime.now(),
repoid=repo.repoid,
branch="feature",
Expand All @@ -914,24 +914,24 @@ def test_branch_filter_on_test_results(self) -> None:
def test_commits_failed_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
commitid="1",
commits_where_fail=["1"],
)
_test_instance_2 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
commitid="2",
commits_where_fail=["2"],
)
test_2 = TestFactory(repository=repo)
_test_instance_3 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test_2,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
commitid="3",
commits_where_fail=["3"],
)
res = self.fetch_repository(
repo.name,
Expand All @@ -947,24 +947,24 @@ def test_commits_failed_ordering_on_test_results(self) -> None:
def test_desc_commits_failed_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
commitid="1",
commits_where_fail=["1"],
)
_test_instance_2 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
commitid="2",
commits_where_fail=["2"],
)
test_2 = TestFactory(repository=repo)
_test_instance_3 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test_2,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
commitid="3",
commits_where_fail=["3"],
)
res = self.fetch_repository(
repo.name,
Expand All @@ -977,27 +977,98 @@ def test_desc_commits_failed_ordering_on_test_results(self) -> None:
]
}

def test_last_duration_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_ = DailyTestRollupFactory(
test=test,
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
last_duration_seconds=1,
latest_run=datetime.datetime.now() - datetime.timedelta(days=1),
)
_ = DailyTestRollupFactory(
test=test,
date=datetime.date.today(),
repoid=repo.repoid,
last_duration_seconds=2,
latest_run=datetime.datetime.now(),
)
test_2 = TestFactory(repository=repo)
_ = DailyTestRollupFactory(
test=test_2,
date=datetime.date.today(),
repoid=repo.repoid,
last_duration_seconds=3,
)
res = self.fetch_repository(
repo.name,
"""testResults(ordering: { parameter: LAST_DURATION, direction: ASC }) { edges { node { name lastDuration } } }""",
)
assert res["testResults"] == {
"edges": [
{"node": {"name": test.name, "lastDuration": 2.0}},
{"node": {"name": test_2.name, "lastDuration": 3.0}},
]
}

def test_desc_last_duration_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_ = DailyTestRollupFactory(
test=test,
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
last_duration_seconds=1,
latest_run=datetime.datetime.now() - datetime.timedelta(days=1),
)
_ = DailyTestRollupFactory(
test=test,
date=datetime.date.today(),
repoid=repo.repoid,
last_duration_seconds=2,
latest_run=datetime.datetime.now(),
)
test_2 = TestFactory(repository=repo)
_ = DailyTestRollupFactory(
test=test_2,
date=datetime.date.today(),
repoid=repo.repoid,
last_duration_seconds=3,
)
res = self.fetch_repository(
repo.name,
"""testResults(ordering: { parameter: LAST_DURATION, direction: DESC }) { edges { node { name lastDuration } } }""",
)
assert res["testResults"] == {
"edges": [
{"node": {"name": test_2.name, "lastDuration": 3}},
{"node": {"name": test.name, "lastDuration": 2}},
]
}

def test_avg_duration_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
test = TestFactory(repository=repo)
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
duration_seconds=1,
avg_duration_seconds=1,
)
_test_instance_2 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
duration_seconds=2,
avg_duration_seconds=2,
)
test_2 = TestFactory(repository=repo)
_test_instance_3 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test_2,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
duration_seconds=3,
avg_duration_seconds=3,
)
res = self.fetch_repository(
repo.name,
Expand All @@ -1013,24 +1084,24 @@ def test_avg_duration_ordering_on_test_results(self) -> None:
def test_desc_avg_duration_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
duration_seconds=1,
avg_duration_seconds=1,
)
_test_instance_2 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
duration_seconds=2,
avg_duration_seconds=2,
)
test_2 = TestFactory(repository=repo)
_test_instance_3 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test_2,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
duration_seconds=3,
avg_duration_seconds=3,
)
res = self.fetch_repository(
repo.name,
Expand All @@ -1046,30 +1117,27 @@ def test_desc_avg_duration_ordering_on_test_results(self) -> None:
def test_failure_rate_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
outcome="pass",
pass_count=1,
fail_count=1,
)
_test_instance_2 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
outcome="failure",
pass_count=3,
fail_count=0,
)
test_2 = TestFactory(repository=repo)
_test_instance_3 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test_2,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
outcome="failure",
)
_test_instance_4 = TestInstanceFactory(
test=test_2,
created_at=datetime.datetime.now(),
repoid=repo.repoid,
outcome="failure",
pass_count=2,
fail_count=3,
)
res = self.fetch_repository(
repo.name,
Expand All @@ -1078,38 +1146,35 @@ def test_failure_rate_ordering_on_test_results(self) -> None:

assert res["testResults"] == {
"edges": [
{"node": {"name": test.name, "failureRate": 0.5}},
{"node": {"name": test_2.name, "failureRate": 1.0}},
{"node": {"name": test.name, "failureRate": 0.2}},
{"node": {"name": test_2.name, "failureRate": 0.6}},
]
}

def test_desc_failure_rate_ordering_on_test_results(self) -> None:
repo = RepositoryFactory(author=self.owner, active=True, private=True)
test = TestFactory(repository=repo)
_test_instance_1 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today() - datetime.timedelta(days=1),
repoid=repo.repoid,
outcome="pass",
pass_count=1,
fail_count=1,
)
_test_instance_2 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
outcome="failure",
pass_count=3,
fail_count=0,
)
test_2 = TestFactory(repository=repo)
_test_instance_3 = TestInstanceFactory(
test=test_2,
created_at=datetime.datetime.now(),
repoid=repo.repoid,
outcome="failure",
)
_test_instance_4 = TestInstanceFactory(
_ = DailyTestRollupFactory(
test=test_2,
created_at=datetime.datetime.now(),
date=datetime.date.today(),
repoid=repo.repoid,
outcome="failure",
pass_count=2,
fail_count=3,
)
res = self.fetch_repository(
repo.name,
Expand All @@ -1118,7 +1183,7 @@ def test_desc_failure_rate_ordering_on_test_results(self) -> None:

assert res["testResults"] == {
"edges": [
{"node": {"name": test_2.name, "failureRate": 1.0}},
{"node": {"name": test.name, "failureRate": 0.5}},
{"node": {"name": test_2.name, "failureRate": 0.6}},
{"node": {"name": test.name, "failureRate": 0.2}},
]
}
Loading
Loading