Files
s41r4j 0f03d49514
CI / contracts (push) Canceled after 0s
Website / deploy (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-24.04) (push) Canceled after 0s
CI / test (ubuntu-24.04-arm) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / operation-readiness (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
Initial commit
2026-11-01 09:14:18 +05:30

40 lines
853 B
Go

package execution
import (
"context"
"github.com/s41r4j/cybot/pkg/schema"
"sync/atomic"
"testing"
"time"
)
type fakeRunner struct{ active, max atomic.Int32 }
func (f *fakeRunner) Health(context.Context, schema.Tool) error { return nil }
func (f *fakeRunner) Run(context.Context, Spec) (Output, error) {
n := f.active.Add(1)
for {
m := f.max.Load()
if n <= m || f.max.CompareAndSwap(m, n) {
break
}
}
time.Sleep(10 * time.Millisecond)
f.active.Add(-1)
return Output{}, nil
}
func TestBoundedRunnerLimitsConcurrency(t *testing.T) {
base := &fakeRunner{}
r := NewBounded(base, 2, 0)
done := make(chan bool)
for i := 0; i < 6; i++ {
go func() { _, _ = r.Run(context.Background(), Spec{}); done <- true }()
}
for i := 0; i < 6; i++ {
<-done
}
if base.max.Load() > 2 {
t.Fatalf("max concurrency %d", base.max.Load())
}
}