perf: sync protocol and core hardening updates

This commit is contained in:
A 2026-07-11 19:48:26 +08:00
parent 152fed3b87
commit 4390ebf5a9
283 changed files with 29231 additions and 2295 deletions

View file

@ -1,6 +1,8 @@
package rpc
import (
"context"
"sync/atomic"
"testing"
"time"
)
@ -27,6 +29,35 @@ func TestIdleBackoffSequenceAndReset(t *testing.T) {
}
}
func TestIdleBackoffLoopDrainsActiveWorkImmediately(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var calls atomic.Int32
done := make(chan struct{})
started := time.Now()
go func() {
defer close(done)
runIdleBackoffLoop(ctx, time.Second, time.Second, func(context.Context) bool {
if calls.Add(1) < 4 {
return true
}
cancel()
return false
})
}()
select {
case <-done:
case <-time.After(300 * time.Millisecond):
t.Fatal("active drain waited for idle interval")
}
if got := calls.Load(); got != 4 {
t.Fatalf("dispatch calls = %d, want 4 consecutive active drains", got)
}
if elapsed := time.Since(started); elapsed >= 300*time.Millisecond {
t.Fatalf("active drain elapsed = %v, want no 1s base delay", elapsed)
}
}
func TestIdleBackoffSanitizesMaxBelowBase(t *testing.T) {
backoff := newIdleBackoff(2*time.Second, time.Second)
if got := backoff.IdleDelay(); got != 2*time.Second {