Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/pool/pool_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func (p *SingleConnPool) Put(ctx context.Context, cn *Conn) {}
func (p *SingleConnPool) Remove(ctx context.Context, cn *Conn, reason error) {
p.cn = nil
p.stickyErr = reason
if reason == nil && ctx != nil {
p.stickyErr = ctx.Err()
}
}

func (p *SingleConnPool) Close() error {
Expand Down
31 changes: 31 additions & 0 deletions internal/pool/pool_single_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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() {
var p *pool.SingleConnPool

BeforeEach(func() {
p = pool.NewSingleConnPool(nil, &pool.Conn{})
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this need to be a before each and a variable in this scope? Or could the pool just get moved into the test itself since there is only one?

Copy link
Contributor Author

@xin-tsla xin-tsla Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! It is more clean, addressed: 9653a28


It("remove a conn due to context is cancelled", func() {
ctx, cl := context.WithCancel(context.TODO())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename cl to cancel to make it clear here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, renamed: ec32de7

cn, err := p.Get(nil)
Expect(err).To(BeNil())
Expect(cn).ToNot(BeNil())

cl()
p.Remove(ctx, cn, nil)
cn, err = p.Get(nil)
Expect(cn).To(BeNil())
Expect(err).ToNot(BeNil())
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick, no need for this extra newline

Copy link
Contributor Author

@xin-tsla xin-tsla Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed along with a previous commit 9653a28

})