Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Add support for max-count param in /api/runs #298

Merged
merged 2 commits into from
Nov 24, 2017

Conversation

lukebjerring
Copy link
Collaborator

@lukebjerring lukebjerring commented Nov 24, 2017

See #301

@foolip
Copy link
Member

foolip commented Nov 24, 2017

A description in the first commit / description would be very nice, both for context when reviewing and when finding this in git blame later.

@lukebjerring
Copy link
Collaborator Author

Commit history cleaned up, PTAL

Copy link
Member

@foolip foolip left a comment

Choose a reason for hiding this comment

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

LGTM % nits if there's nothing exciting in the next commit

baseQuery := datastore.NewQuery("TestRun").Order("-CreatedAt").Limit(1)
var limit int
if limit, err = ParseMaxCountParam(r); err != nil {
http.Error(w, "Invalid 'max-count' param: "+err.Error(), http.StatusBadRequest)
Copy link
Member

Choose a reason for hiding this comment

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

Aside: I don't know Go, but am wondering if runtime error exist, and if so how easy/hard it is to write error handling code that's untested and will actually blow up in a different way than intended if run. (Reminds me of a C++ code base I worked on with a lot of out-of-memory handling that was untested.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some reading for your leisure time: https://blog.golang.org/defer-panic-and-recover

params.go Outdated
// ParseMaxCountParam parses the 'max-count' parameter as an integer.
func ParseMaxCountParam(r *http.Request) (count int, err error) {
count = MaxCountDefaultValue
if browsersParam := r.URL.Query().Get("max-count"); browsersParam != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Should this by maxCountParam or countParam instead of browsersParam?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed (CopyPasta)

}

func TestParseMaxCountParam_TooSmall(t *testing.T) {
r := httptest.NewRequest("GET", "http://wpt.fyi/?max-count=0", nil)
Copy link
Member

Choose a reason for hiding this comment

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

Also try max-count=-1 or max-count=1e8 to see that the "not a non-negative integer" error handling is right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

util.go Outdated
@@ -47,6 +47,11 @@ func GetBrowsers() (map[string]Browser, error) {
// GetBrowserNames returns an alphabetically-ordered array of the names
// of the browsers returned by GetBrowsers.
func GetBrowserNames() ([]string, error) {
if browserNamesAlphabetical == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is this change accidentally in this PR, or was it a necessary adjustment?

@lukebjerring lukebjerring merged commit ab1a9c6 into web-platform-tests:master Nov 24, 2017
@lukebjerring lukebjerring deleted the max-count-param branch November 24, 2017 21:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants