75f3dd141c
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CI and Release / lint-frontend (push) Has been cancelled
CI and Release / dockerfile-scan (push) Has been cancelled
CI and Release / test-frontend (push) Has been cancelled
CI and Release / lint-verification-agent (push) Has been cancelled
CI and Release / test-verification-agent (push) Has been cancelled
CI and Release / e2e-verification-agent (push) Has been cancelled
CI and Release / test-backend (push) Has been cancelled
CI and Release / build-dev-image (push) Has been cancelled
CI and Release / push-dev-image (push) Has been cancelled
CI and Release / build-image (push) Has been cancelled
CI and Release / build-verification-image (push) Has been cancelled
CI and Release / determine-version (push) Has been cancelled
CI and Release / push-image (push) Has been cancelled
CI and Release / push-verification-image (12) (push) Has been cancelled
CI and Release / lint-backend (push) Has been cancelled
CI and Release / push-verification-image (17) (push) Has been cancelled
CI and Release / push-verification-image (18) (push) Has been cancelled
CI and Release / release (push) Has been cancelled
CI and Release / publish-helm-chart (push) Has been cancelled
CI and Release / push-verification-image (13) (push) Has been cancelled
CI and Release / push-verification-image (14) (push) Has been cancelled
CI and Release / push-verification-image (15) (push) Has been cancelled
CI and Release / push-verification-image (16) (push) Has been cancelled
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package runner
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_Pool_Saturated_ReflectsSlotOccupancyAsJobsStartAndFinish(t *testing.T) {
|
|
pool := NewPool(2)
|
|
assert.False(t, pool.Saturated())
|
|
|
|
release := make(chan struct{})
|
|
var started sync.WaitGroup
|
|
started.Add(2)
|
|
|
|
for range 2 {
|
|
pool.Go(func() {
|
|
started.Done()
|
|
<-release
|
|
})
|
|
}
|
|
|
|
started.Wait()
|
|
assert.True(t, pool.Saturated(), "pool must report saturated at MaxConcurrentJobs")
|
|
|
|
close(release)
|
|
pool.Wait()
|
|
assert.False(t, pool.Saturated(), "slots must be released when jobs finish")
|
|
}
|
|
|
|
func Test_Pool_WhenFloodedWithJobs_NeverExceedsCapAndWaitDrainsAll(t *testing.T) {
|
|
const capLimit = 4
|
|
pool := NewPool(capLimit)
|
|
|
|
var concurrent, maxConcurrent atomic.Int32
|
|
|
|
for range 100 {
|
|
pool.Go(func() {
|
|
cur := concurrent.Add(1)
|
|
for {
|
|
observed := maxConcurrent.Load()
|
|
if cur <= observed || maxConcurrent.CompareAndSwap(observed, cur) {
|
|
break
|
|
}
|
|
}
|
|
|
|
concurrent.Add(-1)
|
|
})
|
|
}
|
|
|
|
pool.Wait()
|
|
|
|
assert.LessOrEqual(t, int(maxConcurrent.Load()), capLimit,
|
|
"concurrency must never exceed the slot count")
|
|
assert.Equal(t, int32(0), concurrent.Load(), "Wait must drain every job")
|
|
}
|