Skip to content

Commit 91a2160

Browse files
committed
add WithContext() calls to each test handler
Want to catch issues with using Context objects in tests. Instigated by a deadlock bug (pkg#280) when calling WithContext(). This triggers that bug.
1 parent a741a7f commit 91a2160

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

request-example.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func InMemHandler() Handlers {
2626

2727
// Example Handlers
2828
func (fs *root) Fileread(r *Request) (io.ReaderAt, error) {
29+
_ = r.WithContext(r.Context())
2930
if fs.mockErr != nil {
3031
return nil, fs.mockErr
3132
}
@@ -45,6 +46,7 @@ func (fs *root) Fileread(r *Request) (io.ReaderAt, error) {
4546
}
4647

4748
func (fs *root) Filewrite(r *Request) (io.WriterAt, error) {
49+
_ = r.WithContext(r.Context())
4850
if fs.mockErr != nil {
4951
return nil, fs.mockErr
5052
}
@@ -66,6 +68,7 @@ func (fs *root) Filewrite(r *Request) (io.WriterAt, error) {
6668
}
6769

6870
func (fs *root) Filecmd(r *Request) error {
71+
_ = r.WithContext(r.Context())
6972
if fs.mockErr != nil {
7073
return fs.mockErr
7174
}
@@ -126,6 +129,7 @@ func (f listerat) ListAt(ls []os.FileInfo, offset int64) (int, error) {
126129
}
127130

128131
func (fs *root) Filelist(r *Request) (ListerAt, error) {
132+
_ = r.WithContext(r.Context())
129133
if fs.mockErr != nil {
130134
return nil, fs.mockErr
131135
}

request_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,28 @@ func (t *testHandler) Fileread(r *Request) (io.ReaderAt, error) {
2222
if t.err != nil {
2323
return nil, t.err
2424
}
25+
_ = r.WithContext(r.Context())
2526
return bytes.NewReader(t.filecontents), nil
2627
}
2728

2829
func (t *testHandler) Filewrite(r *Request) (io.WriterAt, error) {
2930
if t.err != nil {
3031
return nil, t.err
3132
}
33+
_ = r.WithContext(r.Context())
3234
return io.WriterAt(t.output), nil
3335
}
3436

3537
func (t *testHandler) Filecmd(r *Request) error {
38+
_ = r.WithContext(r.Context())
3639
return t.err
3740
}
3841

3942
func (t *testHandler) Filelist(r *Request) (ListerAt, error) {
4043
if t.err != nil {
4144
return nil, t.err
4245
}
46+
_ = r.WithContext(r.Context())
4347
f, err := os.Open(r.Filepath)
4448
if err != nil {
4549
return nil, err

0 commit comments

Comments
 (0)