Skip to content

Commit

Permalink
Don't fail is there was some data
Browse files Browse the repository at this point in the history
When reading the output from spokes-receive-pack, sometimes we get "file
already closed" instead of EOF at the end of the output. In that case,
when there is some data, just log the error and proceed to parsing the
data.

This is an attempt to fix or at least learn more about errors like the
one in https://github.com/github/spokes-receive-pack/actions/runs/4629813916/jobs/8190557968.
  • Loading branch information
spraints committed Apr 6, 2023
1 parent 2e77fa7 commit 1c65fc2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/integration/hiderefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestHiderefsConfig(t *testing.T) {
t.Logf("error writing pack to spokes-receive-pack input: %v", err)
}

refStatus, unpackRes, _, err := readResult(bufSRPOut)
refStatus, unpackRes, _, err := readResult(t, bufSRPOut)
require.NoError(t, err)
assert.Equal(t, map[string]string{
createBranch: "ok",
Expand Down
10 changes: 7 additions & 3 deletions internal/integration/nosideband_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,25 @@ func TestNoSideBand(t *testing.T) {

require.NoError(t, srpIn.Close())

lines, err := readResultNoSideBand(bufSRPOut)
lines, err := readResultNoSideBand(t, bufSRPOut)
require.NoError(t, err)
assert.Equal(t, []string{
"unpack ok\n",
"ok refs/heads/newbranch\n",
}, lines)
}

func readResultNoSideBand(r io.Reader) ([]string, error) {
func readResultNoSideBand(t *testing.T, r io.Reader) ([]string, error) {
var lines []string

// Read all of the output so that we can include it with errors.
data, err := io.ReadAll(r)
if err != nil {
return nil, err
if len(data) > 0 {
t.Logf("got data, but there was an error: %v", err)
} else {
return nil, err
}
}

// Replace r.
Expand Down
8 changes: 6 additions & 2 deletions internal/integration/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func readAdv(r io.Reader) (map[string]string, string, error) {
}
}

func readResult(r io.Reader) (map[string]string, string, [][]byte, error) {
func readResult(t *testing.T, r io.Reader) (map[string]string, string, [][]byte, error) {
var (
refStatus map[string]string
unpackRes string
Expand All @@ -61,7 +61,11 @@ func readResult(r io.Reader) (map[string]string, string, [][]byte, error) {
// Read all of the output so that we can include it with errors.
data, err := io.ReadAll(r)
if err != nil {
return nil, "", nil, err
if len(data) > 0 {
t.Logf("got data, but there was an error: %v", err)
} else {
return nil, "", nil, err
}
}

// Replace r.
Expand Down
2 changes: 1 addition & 1 deletion internal/integration/pushoptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestPushOptions(t *testing.T) {

require.NoError(t, srpIn.Close())

refStatus, unpackRes, _, err := readResult(bufSRPOut)
refStatus, unpackRes, _, err := readResult(t, bufSRPOut)
require.NoError(t, err)
assert.Equal(t, map[string]string{
createBranch: "ok",
Expand Down

0 comments on commit 1c65fc2

Please sign in to comment.