Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
remove use of target column on Test table
Browse files Browse the repository at this point in the history
Summary: This is in response to us not being able to migrate anything involving the Test table. This diff stops all code uses of the column target_id on the Test table.

Test Plan: unit tests

Reviewers: anupc

Reviewed By: anupc

Subscribers: changesbot, anupc, kylec

Differential Revision: https://tails.corp.dropbox.com/D225661
  • Loading branch information
Naphat Sanguansin committed Sep 1, 2016
1 parent 78f0975 commit d9b863f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
11 changes: 1 addition & 10 deletions changes/artifacts/bazel_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from changes.constants import Status
from changes.db.utils import get_or_create
from changes.models.bazeltarget import BazelTarget
from changes.models.test import TestCase
from changes.models.testresult import TestResultManager
from changes.storage.artifactstore import ARTIFACTSTORE_PREFIX
from changes.utils.agg import aggregate_result
Expand All @@ -26,18 +25,10 @@ def process(self, fp, artifact):
manager = TestResultManager(self.step, artifact)
manager.save(tests)

# add all tests to target
for test in tests:
test_case = TestCase.query.filter(
TestCase.step == self.step,
TestCase.name_sha == test.name_sha,
).limit(1).first()
target.tests.append(test_case)

# update target metadata
# TODO handle multiple files per target, i.e. sharding and running multiple times
target.status = Status.finished
target.result = aggregate_result([t.result for t in target.tests])
target.result = aggregate_result([t.result for t in tests])
duration = 0
for t in test_suites:
if t.duration is None:
Expand Down
3 changes: 0 additions & 3 deletions changes/models/bazeltarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from datetime import datetime
from sqlalchemy import Column, DateTime, ForeignKey, Text, Integer
from sqlalchemy.orm import backref, relationship

from changes.config import db
from changes.constants import Result, Status
Expand All @@ -23,8 +22,6 @@ class BazelTarget(db.Model):
duration = Column(Integer, default=0)
date_created = Column(DateTime, default=datetime.utcnow, nullable=False)

tests = relationship('TestCase', backref=backref('target'))

def __init__(self, **kwargs):
super(BazelTarget, self).__init__(**kwargs)
if self.id is None:
Expand Down
1 change: 0 additions & 1 deletion changes/models/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class TestCase(db.Model):
job_id = Column(GUID, ForeignKey('job.id', ondelete="CASCADE"), nullable=False)
project_id = Column(GUID, ForeignKey('project.id', ondelete="CASCADE"), nullable=False)
step_id = Column(GUID, ForeignKey('jobstep.id', ondelete="CASCADE"))
target_id = Column(GUID, ForeignKey('bazeltarget.id', ondelete='CASCADE'), nullable=True)
name_sha = Column('label_sha', String(40), nullable=False)
name = Column(Text, nullable=False)
_package = Column('package', Text, nullable=True)
Expand Down
19 changes: 7 additions & 12 deletions tests/changes/artifacts/test_bazel_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from changes.artifacts.bazel_target import BazelTargetHandler
from changes.constants import Result, Status
from changes.models.bazeltarget import BazelTarget
from changes.models.test import TestCase as TestCaseModel
from changes.testutils import (
SAMPLE_XUNIT, SAMPLE_XUNIT_MULTIPLE_SUITES, SAMPLE_XUNIT_MULTIPLE_SUITES_COMPLETE_TIME
)
Expand Down Expand Up @@ -48,10 +49,8 @@ def test_single(self):
assert target.status is Status.finished
assert target.result is Result.failed
assert target.duration == 77
shas = [t.name_sha for t in target.tests]
for test_result in tests:
assert test_result.name_sha in shas
assert len(tests) == len(target.tests)
for t in tests:
TestCaseModel.query.filter(TestCaseModel.name_sha == t.name_sha, TestCaseModel.step == jobstep).exists()

def test_multiple_duration_none(self):
project = self.create_project()
Expand All @@ -73,10 +72,8 @@ def test_multiple_duration_none(self):
assert target.status is Status.finished
assert target.result is Result.failed
assert target.duration is None
shas = [t.name_sha for t in target.tests]
for test_result in tests:
assert test_result.name_sha in shas
assert len(tests) == len(target.tests)
for t in tests:
TestCaseModel.query.filter(TestCaseModel.name_sha == t.name_sha, TestCaseModel.step == jobstep).exists()

def test_multiple_duration_complete(self):
project = self.create_project()
Expand All @@ -98,7 +95,5 @@ def test_multiple_duration_complete(self):
assert target.status is Status.finished
assert target.result is Result.passed
assert target.duration == 1577
shas = [t.name_sha for t in target.tests]
for test_result in tests:
assert test_result.name_sha in shas
assert len(tests) == len(target.tests)
for t in tests:
TestCaseModel.query.filter(TestCaseModel.name_sha == t.name_sha, TestCaseModel.step == jobstep).exists()

0 comments on commit d9b863f

Please sign in to comment.