-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
csbufio: Respect contexts in NewReader/NewWriter (lytics/lio#28503) (PR
#100)
- Loading branch information
Showing
8 changed files
with
167 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package csbufio | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReaderContextDone(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
m := memRWC([]byte("some-data")) | ||
rc := NewReader(ctx, &m) | ||
|
||
var p []byte | ||
n, err := rc.Read(p) | ||
require.ErrorIs(t, err, context.Canceled) | ||
require.Equal(t, 0, n) | ||
require.Len(t, p, 0) | ||
|
||
err = rc.Close() | ||
require.ErrorIs(t, err, context.Canceled) | ||
} | ||
|
||
type memRWC []byte | ||
|
||
func (m memRWC) Read(p []byte) (int, error) { | ||
n := len(p) | ||
if n > len(m) { | ||
n = len(m) | ||
} | ||
copy(p, m) | ||
return n, nil | ||
} | ||
|
||
func (m *memRWC) Write(p []byte) (int, error) { | ||
*m = append(*m, p...) | ||
return len(p), nil | ||
} | ||
|
||
func (m memRWC) Close() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package csbufio | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWriterContextDone(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
var m memRWC | ||
wc := NewWriter(ctx, &m) | ||
|
||
n, err := wc.Write([]byte("some-data")) | ||
require.ErrorIs(t, err, context.Canceled) | ||
require.Equal(t, 0, n) | ||
require.Len(t, m, 0) | ||
|
||
err = wc.Close() | ||
require.ErrorIs(t, err, context.Canceled) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,54 @@ | ||
module github.com/lytics/cloudstorage | ||
|
||
go 1.15 | ||
go 1.18 | ||
|
||
require ( | ||
cloud.google.com/go/storage v1.15.0 | ||
github.com/Azure/azure-sdk-for-go v40.5.0+incompatible | ||
github.com/Azure/go-autorest/autorest v0.11.10 // indirect | ||
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect | ||
github.com/araddon/gou v0.0.0-20190110011759-c797efecbb61 | ||
github.com/aws/aws-sdk-go v1.29.34 | ||
github.com/dnaeon/go-vcr v1.1.0 // indirect | ||
github.com/pborman/uuid v1.2.1 | ||
github.com/pkg/sftp v1.11.0 | ||
github.com/satori/go.uuid v1.2.0 // indirect | ||
github.com/stretchr/testify v1.6.1 | ||
github.com/stretchr/testify v1.8.0 | ||
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 | ||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 | ||
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 | ||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c | ||
google.golang.org/api v0.45.0 | ||
) | ||
|
||
require ( | ||
cloud.google.com/go v0.81.0 // indirect | ||
github.com/Azure/go-autorest v14.2.0+incompatible // indirect | ||
github.com/Azure/go-autorest/autorest v0.11.10 // indirect | ||
github.com/Azure/go-autorest/autorest/adal v0.9.5 // indirect | ||
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect | ||
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect | ||
github.com/Azure/go-autorest/logger v0.2.0 // indirect | ||
github.com/Azure/go-autorest/tracing v0.6.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dnaeon/go-vcr v1.1.0 // indirect | ||
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect | ||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/uuid v1.1.2 // indirect | ||
github.com/googleapis/gax-go/v2 v2.0.5 // indirect | ||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect | ||
github.com/jstemmer/go-junit-report v0.9.1 // indirect | ||
github.com/kr/fs v0.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/satori/go.uuid v1.2.0 // indirect | ||
go.opencensus.io v0.23.0 // indirect | ||
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect | ||
golang.org/x/mod v0.4.1 // indirect | ||
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 // indirect | ||
golang.org/x/text v0.3.5 // indirect | ||
golang.org/x/tools v0.1.0 // indirect | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/genproto v0.0.0-20210420162539-3c870d7478d2 // indirect | ||
google.golang.org/grpc v1.37.0 // indirect | ||
google.golang.org/protobuf v1.26.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters