-
Notifications
You must be signed in to change notification settings - Fork 289
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
Fix an error where exit status wasn't getting captured by the cleanup process #2230
Conversation
2c02c88
to
0357d9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good - I have one or two tweaks
|
||
for _, b := range tae.calls[endpoint] { | ||
var job api.Job | ||
err := json.NewDecoder(bytes.NewBuffer(b)).Decode(&job) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err := json.NewDecoder(bytes.NewBuffer(b)).Decode(&job) | |
err := json.Unmarshal(b, &job) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, duh
@@ -230,7 +280,7 @@ func (t *testAgentEndpoint) server(jobID string) *httptest.Server { | |||
case "/jobs/" + jobID + "/finish": | |||
rw.WriteHeader(http.StatusOK) | |||
default: | |||
http.Error(rw, fmt.Sprintf("not found; method = %q, path = %q", req.Method, req.URL.Path), http.StatusNotFound) | |||
panic(fmt.Sprintf("not found; method = %q, path = %q", req.Method, req.URL.Path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this change for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about this too. Is it because you need a json error message? I think you should craft one if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a relic from when i was bughunting and flailing a bit; i think my logic was that if an endpoint that we haven't accounted for is hit it's a Very Bad Thing, and i don't think these errors are super well surfaced in the tests???? maybe? but also this doesn't really need to be here, i might just yeet it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to return a 4xx error in such circumstances and raise an error from the Test method. It will be easier to debug how the route was called then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the error handling could happen entirely in the non-test code. Hopefully, writing code that ignores errors is something we have gotten out of the habit of doing.
@@ -214,6 +248,22 @@ func createTestAgentEndpoint() *testAgentEndpoint { | |||
} | |||
} | |||
|
|||
func (tae *testAgentEndpoint) finishesFor(t *testing.T, jobID string) []api.Job { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (tae *testAgentEndpoint) finishesFor(t *testing.T, jobID string) []api.Job { | |
func (tae *testAgentEndpoint) finishesFor(t *testing.T, jobID string) []api.Job { | |
t.Helper() |
so that if an error occurs in this method, the output will show a line number from the test method.
0357d9c
to
9fb5b97
Compare
9fb5b97
to
a615d96
Compare
tl;dr before:
after:
previously we were capturing the value of
exit
at the time of the call todefer
, now we're capturing the value at the time the defer is actually executed, which is what we wanted in the first place.this PR also adds a regression test to ensure that this doesn't happen again