diff --git a/src/caduceus/caduceus_type.go b/src/caduceus/caduceus_type.go index 8a3d3d41..67189ba7 100644 --- a/src/caduceus/caduceus_type.go +++ b/src/caduceus/caduceus_type.go @@ -17,7 +17,6 @@ package main import ( - "errors" "github.com/Comcast/webpa-common/logging" "github.com/Comcast/webpa-common/secure" "github.com/Comcast/webpa-common/secure/key" @@ -78,43 +77,3 @@ func (ch *CaduceusHandler) HandleRequest(workerID int, msg *wrp.Message) { " to sender") ch.senderWrapper.Queue(msg) } - -// Below is the struct and implementation of our worker pool factory -type WorkerPoolFactory struct { - NumWorkers int - QueueSize int -} - -func (wpf WorkerPoolFactory) New() (wp *WorkerPool) { - jobs := make(chan func(workerID int), wpf.QueueSize) - - for i := 0; i < wpf.NumWorkers; i++ { - go func(id int) { - for f := range jobs { - f(id) - } - }(i) - } - - wp = &WorkerPool{ - jobs: jobs, - } - - return -} - -// Below is the struct and implementation of our worker pool -// It utilizes a non-blocking channel, so we throw away any requests that exceed -// the channel's limit (indicated by its buffer size) -type WorkerPool struct { - jobs chan func(workerID int) -} - -func (wp *WorkerPool) Send(inFunc func(workerID int)) error { - select { - case wp.jobs <- inFunc: - return nil - default: - return errors.New("Worker pool channel full.") - } -} diff --git a/src/caduceus/caduceus_type_test.go b/src/caduceus/caduceus_type_test.go index d51bde3d..fcfcb253 100644 --- a/src/caduceus/caduceus_type_test.go +++ b/src/caduceus/caduceus_type_test.go @@ -17,52 +17,13 @@ package main import ( - "sync" "testing" "github.com/Comcast/webpa-common/logging" "github.com/Comcast/webpa-common/wrp" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" ) -func TestWorkerPool(t *testing.T) { - assert := assert.New(t) - - workerPool := WorkerPoolFactory{ - NumWorkers: 1, - QueueSize: 1, - }.New() - - t.Run("TestWorkerPoolSend", func(t *testing.T) { - testWG := new(sync.WaitGroup) - testWG.Add(1) - - require.NotNil(t, workerPool) - err := workerPool.Send(func(workerID int) { - testWG.Done() - }) - - testWG.Wait() - assert.Nil(err) - }) - - workerPool = WorkerPoolFactory{ - NumWorkers: 0, - QueueSize: 0, - }.New() - - t.Run("TestWorkerPoolFullQueue", func(t *testing.T) { - require.NotNil(t, workerPool) - err := workerPool.Send(func(workerID int) { - assert.Fail("This should not execute because our worker queue is full and we have no workers.") - }) - - assert.NotNil(err) - }) -} - func TestCaduceusHandler(t *testing.T) { logger := logging.DefaultLogger()