mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-23 07:10:31 +03:00
Add test for pool
This commit is contained in:
parent
8dfa929666
commit
acba4b16ee
@ -16,6 +16,34 @@ func TestCore(t *testing.T) {
|
||||
RunSpecs(t, "Core Suite")
|
||||
}
|
||||
|
||||
var _ = Describe("Pool", func() {
|
||||
type testItem struct {
|
||||
ID int
|
||||
}
|
||||
|
||||
type results []int
|
||||
|
||||
func (r results) Len() int { return len(r) }
|
||||
|
||||
var processed results
|
||||
|
||||
var _ = Describe("Pool", func() {
|
||||
var pool *Pool
|
||||
|
||||
BeforeEach(func() {
|
||||
processed = nil
|
||||
pool, _ = NewPool("test", 2, &testItem{}, execute)
|
||||
})
|
||||
|
||||
It("processes items", func() {
|
||||
for i := 0; i < 5; i++ {
|
||||
pool.Submit(&testItem{ID: i})
|
||||
}
|
||||
Eventually(processed.Len).Should(Equal(5))
|
||||
Expect(processed).To(ContainElements(0, 1, 2, 3, 4))
|
||||
})
|
||||
})
|
||||
|
||||
func execute(workload interface{}) {
|
||||
item := workload.(*testItem)
|
||||
processed = append(processed, item.ID)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user