Files
shater/route/idle_suspend_stub_lx_test.go
Leadaxe 1cbd3deb4f feat(spec-020): gate idle-suspend behind with_lx_idle_suspend (mobile-only)
Idle-suspend frees the recv-worker bufsArrs, which are ~8MB each only where
BatchSize=128 (Android/Linux) — on desktop BatchSize is small and the feature
saves almost nothing. Make that platform scope explicit in the build instead of
running the tick everywhere.

The idle-suspend tick now compiles only with the new `with_lx_idle_suspend` tag,
baked into the mobile AAR (build_libbox sharedTags) but NOT the desktop LX_TAGS.
Without the tag, a config that sets route.lx_idle_suspend fails fast at start
("rebuild with -tags with_lx_idle_suspend (mobile-only feature)") rather than a
silent no-op. The gate is a single function: reachability_lx.go carries the tick
under the tag, idle_suspend_stub_lx.go is the no-tag stub that errors, and
reachability_common_lx.go keeps InvalidateReachability (needed by the group
interface in every build). The dial hot path (resumeOnDial/stampActivity) and the
upstream group files are untouched — without the tick, idleAsleep is never set, so
resumeOnDial always takes its fast path.

Adds stub unit tests (option set → error, unset → no-op). Both build variants and
the full route/wireguard/group suites are green; gofmt/vet clean; desktop lx-check
passes without the tag. Docs (lx-config.md + ru, SPEC.md §3/§10) describe the tag.
2026-07-01 11:38:36 +03:00

31 lines
969 B
Go

//go:build !with_lx_idle_suspend
// lx:begin idle-suspend
package route
import (
"testing"
"time"
)
// TestStartIdleSuspend_stubErrorsWhenOptionSet: without the build tag, a config
// that sets lx_idle_suspend must fail loudly at start, not silently no-op.
func TestStartIdleSuspend_stubErrorsWhenOptionSet(t *testing.T) {
r := &Router{idleSuspend: 30 * time.Second}
if err := r.startIdleSuspend(); err == nil {
t.Fatal("expected an error when lx_idle_suspend is set in a build without with_lx_idle_suspend")
}
}
// TestStartIdleSuspend_stubNoopWhenUnset: without the option, the stub is a clean
// no-op (no error) — desktop builds with no lx_idle_suspend are unaffected.
func TestStartIdleSuspend_stubNoopWhenUnset(t *testing.T) {
r := &Router{} // idleSuspend == 0
if err := r.startIdleSuspend(); err != nil {
t.Fatalf("stub must be a no-op when the option is unset, got %v", err)
}
r.stopIdleSuspend() // must not panic
}
// lx:end idle-suspend