From 216491815c4e205d76f5f6cafe53e3940f2a81cb Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 27 Oct 2020 15:43:00 -0400 Subject: [PATCH] Increased pool test timeout (hate time based tests...) --- core/pool/pool.go | 23 ++++++++++++----------- core/pool/pool_test.go | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/pool/pool.go b/core/pool/pool.go index f781480a..6184fd79 100644 --- a/core/pool/pool.go +++ b/core/pool/pool.go @@ -3,13 +3,14 @@ package pool type Executor func(workload interface{}) type Pool struct { - name string - item interface{} - workers []worker - exec Executor + name string + item interface{} + workers []worker + exec Executor + workerChannel chan chan work + queue chan work // receives jobs to send to workers + end chan bool // when receives bool stops workers //queue *dque.DQue - queue chan work // receives jobs to send to workers - end chan bool // when receives bool stops workers } func NewPool(name string, workerCount int, item interface{}, exec Executor) (*Pool, error) { @@ -26,12 +27,14 @@ func NewPool(name string, workerCount int, item interface{}, exec Executor) (*Po // return nil, err //} //p.queue = q + + p.workerChannel = make(chan chan work) for i := 0; i < workerCount; i++ { worker := worker{ p: p, id: i, channel: make(chan work), - workerChannel: workerChannel, + workerChannel: p.workerChannel, end: make(chan bool)} worker.Start() p.workers = append(p.workers, worker) @@ -47,8 +50,8 @@ func NewPool(name string, workerCount int, item interface{}, exec Executor) (*Po } return case work := <-p.queue: - worker := <-workerChannel // wait for available channel - worker <- work // dispatch work to worker + worker := <-p.workerChannel // wait for available channel + worker <- work // dispatch work to worker } } }() @@ -64,8 +67,6 @@ func (p *Pool) Submit(workload interface{}) { // return reflect.New(t).Interface() //} // -var workerChannel = make(chan chan work) - type work struct { workload interface{} } diff --git a/core/pool/pool_test.go b/core/pool/pool_test.go index d7fe4450..ed01c82d 100644 --- a/core/pool/pool_test.go +++ b/core/pool/pool_test.go @@ -38,7 +38,7 @@ var _ = Describe("Pool", func() { for i := 0; i < 5; i++ { pool.Submit(&testItem{ID: i}) } - Eventually(processed.Len).Should(Equal(5)) + Eventually(processed.Len, "10s").Should(Equal(5)) Expect(processed).To(ContainElements(0, 1, 2, 3, 4)) }) })