Skip to content

Commit

Permalink
Merge pull request #121 from Comcast/prune-dead-code
Browse files Browse the repository at this point in the history
Prune some dead code.
  • Loading branch information
schmidtw authored Feb 20, 2019
2 parents 2666acf + 5b44862 commit f02c62e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
41 changes: 0 additions & 41 deletions src/caduceus/caduceus_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.")
}
}
39 changes: 0 additions & 39 deletions src/caduceus/caduceus_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit f02c62e

Please sign in to comment.