Skip to content

Commit

Permalink
internal/gomote: fix flaky TestWriteFileFromURL test
Browse files Browse the repository at this point in the history
This change fixes a flaky test introduced in CL 397596.
The test was unnecessarily downloading a file from the go.dev site.
It was also not providing enough data to fix the issue when the test
failed.

Fixes golang/go#52671

Change-Id: Ie42501c197395538376debd510cfb993d697401d
Reviewed-on: https://go-review.googlesource.com/c/build/+/405516
Run-TryBot: Carlos Amedee <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
Auto-Submit: Carlos Amedee <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
  • Loading branch information
cagedmantis authored and gopherbot committed May 10, 2022
1 parent 140d723 commit 5d48fa5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/gomote/gomote.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (s *Server) WriteFileFromURL(ctx context.Context, req *protos.WriteFileFrom
return nil, status.Errorf(codes.Aborted, "failed to get file from URL: %s", err)
}
if resp.StatusCode != http.StatusOK {
return nil, status.Errorf(codes.Aborted, "unable to get file from URL: response code: %d", resp.StatusCode)
return nil, status.Errorf(codes.Aborted, "unable to get file from %q: response code: %d", req.GetUrl(), resp.StatusCode)
}
rc = resp.Body
}
Expand Down
8 changes: 7 additions & 1 deletion internal/gomote/gomote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
"time"

Expand Down Expand Up @@ -788,9 +790,13 @@ func TestWriteFileFromURL(t *testing.T) {
ctx := access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP())
client := setupGomoteTest(t, context.Background())
gomoteID := mustCreateInstance(t, client, fakeIAP())
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Go is an open source programming language")
}))
defer ts.Close()
if _, err := client.WriteFileFromURL(ctx, &protos.WriteFileFromURLRequest{
GomoteId: gomoteID,
Url: `https://go.dev/dl/go1.17.6.linux-amd64.tar.gz`,
Url: ts.URL,
Filename: "foo",
Mode: 0777,
}); err != nil {
Expand Down

0 comments on commit 5d48fa5

Please sign in to comment.