Files
Agent-Native/exec/limiter_test.go
T
weichen 6ddd3da8df Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:36:10 +00:00

51 lines
1000 B
Go

package exec_test
import (
"context"
"sync"
"sync/atomic"
"testing"
"time"
"git-ssh.u1680832.nyat.app/weichen/Agent-Native.git/exec"
)
type slowBackend struct {
running atomic.Int32
peak atomic.Int32
}
func (s *slowBackend) Name() string { return "slow" }
func (s *slowBackend) Execute(ctx context.Context, req exec.Request) (*exec.Result, error) {
cur := s.running.Add(1)
for {
p := s.peak.Load()
if cur <= p || s.peak.CompareAndSwap(p, cur) {
break
}
}
time.Sleep(40 * time.Millisecond)
s.running.Add(-1)
return &exec.Result{Success: true}, nil
}
func TestLimitingBackendCapsConcurrency(t *testing.T) {
inner := &slowBackend{}
limited := exec.WrapWithConcurrencyLimit(inner, 2)
var wg sync.WaitGroup
for i := 0; i < 6; i++ {
wg.Add(1)
go func() {
defer wg.Done()
_, _ = limited.Execute(context.Background(), exec.Request{})
}()
}
wg.Wait()
if peak := inner.peak.Load(); peak > 2 {
t.Fatalf("expected peak concurrency <= 2, got %d", peak)
}
}