add comment about purpose of context use in example/tests
diff --git a/request-example.go b/request-example.go
index ddc85aa..e5abd18 100644
--- a/request-example.go
+++ b/request-example.go
@@ -27,10 +27,10 @@
// Example Handlers
func (fs *root) Fileread(r *Request) (io.ReaderAt, error) {
- _ = r.WithContext(r.Context())
if fs.mockErr != nil {
return nil, fs.mockErr
}
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
fs.filesLock.Lock()
defer fs.filesLock.Unlock()
file, err := fs.fetch(r.Filepath)
@@ -47,10 +47,10 @@
}
func (fs *root) Filewrite(r *Request) (io.WriterAt, error) {
- _ = r.WithContext(r.Context())
if fs.mockErr != nil {
return nil, fs.mockErr
}
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
fs.filesLock.Lock()
defer fs.filesLock.Unlock()
file, err := fs.fetch(r.Filepath)
@@ -69,10 +69,10 @@
}
func (fs *root) Filecmd(r *Request) error {
- _ = r.WithContext(r.Context())
if fs.mockErr != nil {
return fs.mockErr
}
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
fs.filesLock.Lock()
defer fs.filesLock.Unlock()
switch r.Method {
@@ -130,10 +130,10 @@
}
func (fs *root) Filelist(r *Request) (ListerAt, error) {
- _ = r.WithContext(r.Context())
if fs.mockErr != nil {
return nil, fs.mockErr
}
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
fs.filesLock.Lock()
defer fs.filesLock.Unlock()
diff --git a/request_test.go b/request_test.go
index 44773d7..b3d7716 100644
--- a/request_test.go
+++ b/request_test.go
@@ -22,7 +22,7 @@
if t.err != nil {
return nil, t.err
}
- _ = r.WithContext(r.Context())
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
return bytes.NewReader(t.filecontents), nil
}
@@ -30,12 +30,12 @@
if t.err != nil {
return nil, t.err
}
- _ = r.WithContext(r.Context())
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
return io.WriterAt(t.output), nil
}
func (t *testHandler) Filecmd(r *Request) error {
- _ = r.WithContext(r.Context())
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
return t.err
}
@@ -43,7 +43,7 @@
if t.err != nil {
return nil, t.err
}
- _ = r.WithContext(r.Context())
+ _ = r.WithContext(r.Context()) // initialize context for deadlock testing
f, err := os.Open(r.Filepath)
if err != nil {
return nil, err