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

Checks: Plumb channel and improve robustness of diff urls #889

Merged
merged 10 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion api/checks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s checksAPIImpl) PendingCheckRun(suite shared.CheckSuite, product shared.P
TestRun: nil, // It's pending, no run exists yet.
Product: product,
HeadSHA: suite.SHA,
DetailsURL: shared.NewDiffAPI(s.ctx).GetMasterDiffURL(suite.SHA, product),
DetailsURL: shared.NewDiffAPI(s.ctx).GetMasterDiffURL(suite.SHA, product, nil),
Status: "in_progress",
},
HostName: host,
Expand Down
10 changes: 7 additions & 3 deletions api/checks/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ func getDiffSummary(aeAPI shared.AppEngineAPI, diffAPI shared.DiffAPI, baseRun,
checkState := summaries.CheckState{
Hexcles marked this conversation as resolved.
Show resolved Hide resolved
TestRun: &headRun,
Product: shared.ProductSpec{
ProductAtRevision: headRun.ProductAtRevision,
Labels: labels,
// [browser]@[sha] is plenty specific, and avoids bad version strings.
Copy link
Member

Choose a reason for hiding this comment

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

This is probably not specific enough in some cases.

Example: when headRun is a PR run, we would only pass browser[channel]@revision to GetMasterDiffURL, which will match to both pr_base and pr_head runs, and the users would always expect the pr_head run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is deliberately the case. This only needs to identify any runs precisely enough for a given check; i.e. the CheckState's product is specific enough to identify chrome[experimental], and what the means as a check depends on what's been run (e.g. master vs an earlier master, pr_base vs pr_head, etc.)

As for below, let's rejig the API to take a run to diff against master, and then we can be less ambiguous :)

ProductAtRevision: shared.ProductAtRevision{
Product: shared.Product{BrowserName: headRun.BrowserName},
Revision: headRun.Revision,
},
Labels: labels,
},
HeadSHA: headRun.FullRevisionHash,
DetailsURL: diffURL,
Expand All @@ -194,7 +198,7 @@ func getDiffSummary(aeAPI shared.AppEngineAPI, diffAPI shared.DiffAPI, baseRun,
HostName: host,
HostURL: fmt.Sprintf("https://%s/", host),
DiffURL: diffURL.String(),
MasterDiffURL: diffAPI.GetMasterDiffURL(checkState.HeadSHA, checkState.Product).String(),
MasterDiffURL: diffAPI.GetMasterDiffURL(checkState.HeadSHA, checkState.Product, nil).String(),
}

hasRegressions := regressions.Cardinality() > 0
Expand Down
4 changes: 2 additions & 2 deletions api/checks/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestGetDiffSummary_Regressed(t *testing.T) {
diffAPI.EXPECT().GetRunsDiff(before, after, gomock.Any(), gomock.Any()).Return(runDiff, nil)
diffURL, _ := url.Parse("https://wpt.fyi/results?diff")
diffAPI.EXPECT().GetDiffURL(before, after, gomock.Any()).Return(diffURL)
diffAPI.EXPECT().GetMasterDiffURL(after.FullRevisionHash, sharedtest.SameProductSpec(before.BrowserName)).Return(diffURL)
diffAPI.EXPECT().GetMasterDiffURL(after.FullRevisionHash, sharedtest.SameProductSpec(before.BrowserName), nil).Return(diffURL)

summary, err := getDiffSummary(aeAPI, diffAPI, before, after)
assert.Nil(t, err)
Expand All @@ -57,7 +57,7 @@ func TestGetDiffSummary_Completed(t *testing.T) {
diffAPI.EXPECT().GetRunsDiff(before, after, gomock.Any(), gomock.Any()).Return(runDiff, nil)
diffURL, _ := url.Parse("https://wpt.fyi/results?diff")
diffAPI.EXPECT().GetDiffURL(before, after, gomock.Any()).Return(diffURL)
diffAPI.EXPECT().GetMasterDiffURL(after.FullRevisionHash, sharedtest.SameProductSpec(before.BrowserName)).Return(diffURL)
diffAPI.EXPECT().GetMasterDiffURL(after.FullRevisionHash, sharedtest.SameProductSpec(before.BrowserName), nil).Return(diffURL)

summary, err := getDiffSummary(aeAPI, diffAPI, before, after)
assert.Nil(t, err)
Expand Down
31 changes: 18 additions & 13 deletions shared/run_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type DiffAPI interface {
GetRunsDiff(before, after TestRun, filter DiffFilterParam, paths mapset.Set) (RunDiff, error)
GetDiffURL(before, after TestRun, diffFilter *DiffFilterParam) *url.URL
GetMasterDiffURL(sha string, product ProductSpec) *url.URL
GetMasterDiffURL(sha string, product ProductSpec, diffFilter *DiffFilterParam) *url.URL
Hexcles marked this conversation as resolved.
Show resolved Hide resolved
}

type diffAPIImpl struct {
Expand All @@ -42,10 +42,11 @@ func NewDiffAPI(ctx context.Context) DiffAPI {

func (d diffAPIImpl) GetDiffURL(before, after TestRun, diffFilter *DiffFilterParam) *url.URL {
filter := TestRunFilter{}
filter.Products = ProductSpecs{
ProductSpec{ProductAtRevision: before.ProductAtRevision},
ProductSpec{ProductAtRevision: after.ProductAtRevision},
}
filter.Products = make(ProductSpecs, 2)
filter.Products[0].BrowserName = before.BrowserName
filter.Products[0].Revision = before.Revision
filter.Products[1].BrowserName = after.BrowserName
filter.Products[1].Revision = after.Revision
detailsURL := d.aeAPI.GetResultsURL(filter)
query := detailsURL.Query()
query.Set("diff", "")
Expand All @@ -56,19 +57,23 @@ func (d diffAPIImpl) GetDiffURL(before, after TestRun, diffFilter *DiffFilterPar
return detailsURL
}

func (d diffAPIImpl) GetMasterDiffURL(sha string, product ProductSpec) *url.URL {
func (d diffAPIImpl) GetMasterDiffURL(sha string, product ProductSpec, diffFilter *DiffFilterParam) *url.URL {
filter := TestRunFilter{}
filter.Products = ProductSpecs{product, product}
filter.Products[0].Labels = mapset.NewSet("master")
filter.Products[1].Revision = sha
filter.Products[0].Revision = "" // No specific SHA for base (master).
if product.Labels == nil {
filter.Products[0].Labels = mapset.NewSet()
}
filter.Products[0].Labels.Add(MasterLabel)

filter.Products[1].Revision = sha // Specific SHA for head.

detailsURL := d.aeAPI.GetResultsURL(filter)
query := detailsURL.Query()
query.Set("diff", "")
query.Set("filter", DiffFilterParam{
Added: true,
Changed: true,
Unchanged: true,
}.String())
if diffFilter != nil {
query.Set("filter", diffFilter.String())
}
detailsURL.RawQuery = query.Encode()
return detailsURL
}
Expand Down
8 changes: 4 additions & 4 deletions shared/sharedtest/run_diff_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion shared/sharedtest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ type sameProductSpec struct {
spec string
}

type stringifiable interface {
String() string
}

func (s sameProductSpec) Matches(x interface{}) bool {
if p, ok := x.(shared.ProductSpec); ok && p.String() == s.spec {
if p, ok := x.(stringifiable); ok && p.String() == s.spec {
return true
} else if str, ok := x.(string); ok && str == s.spec {
return true
Expand Down