discovery & test: Fix goroutine leaks by adding 1 buffer to channel

Signed-off-by: Ziheng Liu <lzhfromustc@gmail.com>
This commit is contained in:
lzhfromustc 2021-03-23 22:50:52 -04:00 committed by Ziheng Liu
parent 7b9275c0da
commit 5ffcd162b5
5 changed files with 9 additions and 9 deletions

View File

@ -108,7 +108,7 @@ func TestWaitCancel(t *testing.T) {
}
ctxCancel, cancel := context.WithCancel(ctx)
chErr := make(chan error)
chErr := make(chan error, 1)
go func() {
chErr <- c.Wait(ctxCancel)
}()
@ -134,7 +134,7 @@ func TestWaitDisabled(t *testing.T) {
t.Fatal(err)
}
chErr := make(chan error)
chErr := make(chan error, 1)
go func() {
chErr <- c.Wait(ctx)
}()
@ -215,7 +215,7 @@ func TestWaitEnabled(t *testing.T) {
t.Fatal(err)
}
chErr := make(chan error)
chErr := make(chan error, 1)
go func() {
chErr <- c.Wait(ctx)
}()

View File

@ -136,7 +136,7 @@ func TestDevmapperLockReleasedDeviceDeletion(t *testing.T) {
// DeviceSet Lock. If lock has not been released, this will hang.
driver.DeviceSet.cleanupDeletedDevices()
doneChan := make(chan bool)
doneChan := make(chan bool, 1)
go func() {
driver.DeviceSet.Lock()

View File

@ -60,8 +60,8 @@ func (s *Discovery) fetch() (discovery.Entries, error) {
// Watch is exported
func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) {
ch := make(chan discovery.Entries)
errCh := make(chan error)
ch := make(chan discovery.Entries, 1)
errCh := make(chan error, 1)
ticker := time.NewTicker(s.heartbeat)
go func() {

View File

@ -33,8 +33,8 @@ func (s *Discovery) Initialize(_ string, heartbeat time.Duration, _ time.Duratio
// Watch sends periodic discovery updates to a channel.
func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) {
ch := make(chan discovery.Entries)
errCh := make(chan error)
ch := make(chan discovery.Entries, 1)
errCh := make(chan error, 1)
ticker := time.NewTicker(s.heartbeat)
go func() {

View File

@ -39,7 +39,7 @@ func (s *Discovery) Initialize(uris string, _ time.Duration, _ time.Duration, _
// Watch is exported
func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) {
ch := make(chan discovery.Entries)
ch := make(chan discovery.Entries, 1)
go func() {
defer close(ch)
ch <- s.entries