Skip to content

Commit

Permalink
Revert: a run can have many contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Apr 27, 2021
1 parent 26a6785 commit 66d8369
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
5 changes: 3 additions & 2 deletions conbench/app/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def page(self, benchmarks, baseline_run, contender_run):
def get(self, run_id):
contender_run, baseline_run = self.get_display_run(run_id), None
if contender_run:
baseline_url = contender_run["links"]["baseline"]
baseline_run = self.get_display_baseline_run(baseline_url)
baseline_url = contender_run["links"].get("baseline")
if baseline_url:
baseline_run = self.get_display_baseline_run(baseline_url)

benchmarks, response = self._get_benchmarks(run_id)
if response.status_code != 200:
Expand Down
16 changes: 14 additions & 2 deletions conbench/entities/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import relationship

from ..entities._entity import Base, EntityMixin, EntitySerializer, NotNull, Nullable
from ..entities.commit import CommitSerializer
from ..entities.commit import Commit, CommitSerializer
from ..entities.machine import MachineSerializer


Expand All @@ -17,6 +17,16 @@ class Run(Base, EntityMixin):
machine_id = NotNull(s.String(50), s.ForeignKey("machine.id"))
machine = relationship("Machine", lazy="joined")

def get_baseline_id(self):
parent = self.commit.parent
runs = Run.search(
filters=[Run.machine_id == self.machine_id, Commit.sha == parent],
joins=[Commit],
)
if runs:
return runs[0].id
return None


class _Serializer(EntitySerializer):
def _dump(self, run):
Expand All @@ -35,7 +45,9 @@ def _dump(self, run):
},
}
if not self.many:
baseline_url = f.url_for("api.run", run_id=run.id, _external=True)
baseline_id, baseline_url = run.get_baseline_id(), None
if baseline_id:
baseline_url = f.url_for("api.run", run_id=baseline_id, _external=True)
result["links"]["baseline"] = baseline_url
return result

Expand Down
20 changes: 14 additions & 6 deletions conbench/tests/api/test_runs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import urllib
import uuid

from ...api._examples import _api_run_entity
from ...entities.summary import Summary
Expand All @@ -17,8 +18,11 @@ def _expected_entity(run, baseline_id=None):
)


def create_benchmark_summary():
def create_benchmark_summary(parent_sha=None):
data = copy.deepcopy(VALID_PAYLOAD)
if parent_sha:
data["run"]["commit"] = parent_sha
data["stats"]["run_id"] = uuid.uuid4().hex
summary = Summary.create(data)
return summary

Expand All @@ -27,15 +31,19 @@ class TestRunGet(_asserts.GetEnforcer):
url = "/api/runs/{}/"
public = True

def _create(self):
summary = create_benchmark_summary()
return summary.run
def _create(self, baseline=False):
contender = create_benchmark_summary()
if baseline:
parent_sha = "4beb514d071c9beec69b8917b5265e77ade22fb3"
baseline = create_benchmark_summary(parent_sha)
return contender.run, baseline.run
return contender.run

def test_get_run(self, client):
self.authenticate(client)
run = self._create()
run, baseline = self._create(baseline=True)
response = client.get(f"/api/runs/{run.id}/")
self.assert_200_ok(response, _expected_entity(run, run.id)) # TODO
self.assert_200_ok(response, _expected_entity(run, baseline.id))


class TestRunList(_asserts.ListEnforcer):
Expand Down

0 comments on commit 66d8369

Please sign in to comment.