-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update err for single conn pool when context.Done() return first (#1981)
* Update err from ctx if reason is nil * Add a unit test * Move pool object to the test itself * Rename a var from cl to cancel * Add comment for explaining why ctx.Err() is used
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pool_test | ||
|
||
import ( | ||
"context" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/go-pg/pg/v10/internal/pool" | ||
) | ||
|
||
var _ = Describe("SingleConnPool", func() { | ||
It("remove a conn due to context is cancelled", func() { | ||
p := pool.NewSingleConnPool(nil, &pool.Conn{}) | ||
ctx, cancel := context.WithCancel(context.TODO()) | ||
cn, err := p.Get(nil) | ||
Expect(err).To(BeNil()) | ||
Expect(cn).ToNot(BeNil()) | ||
|
||
cancel() | ||
p.Remove(ctx, cn, nil) | ||
cn, err = p.Get(nil) | ||
Expect(cn).To(BeNil()) | ||
Expect(err).ToNot(BeNil()) | ||
}) | ||
}) |