quintodrome/core/pool/pool_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
846 B
Go
Raw Normal View History

package pool
import (
"testing"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/tests"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
2021-02-04 11:44:32 -09:00
func TestPool(t *testing.T) {
tests.Init(t, false)
log.SetLevel(log.LevelCritical)
RegisterFailHandler(Fail)
2021-02-04 11:44:32 -09:00
RunSpecs(t, "Pool Suite")
}
2020-10-27 08:27:26 -08:00
type testItem struct {
ID int
}
var processed []int
2020-10-27 08:27:26 -08:00
var _ = Describe("Pool", func() {
2020-10-27 08:27:26 -08:00
var pool *Pool
BeforeEach(func() {
processed = nil
2020-12-15 16:46:52 -09:00
pool, _ = NewPool("test", 2, execute)
2020-10-27 08:27:26 -08:00
})
2020-10-27 08:27:26 -08:00
It("processes items", func() {
for i := 0; i < 5; i++ {
pool.Submit(&testItem{ID: i})
}
Eventually(func() []int { return processed }, "10s").Should(HaveLen(5))
2020-10-27 08:27:26 -08:00
Expect(processed).To(ContainElements(0, 1, 2, 3, 4))
})
})
2020-10-27 08:27:26 -08:00
func execute(workload interface{}) {
item := workload.(*testItem)
processed = append(processed, item.ID)
}