util/syspolicy/rsop: reduce policyReloadMinDelay and policyReloadMaxDelay when in tests

These delays determine how soon syspolicy change callbacks are invoked after a policy setting is updated
in a policy source. For tests, we shorten these delays to minimize unnecessary wait times. This adjustment
only affects tests that subscribe to policy change notifications and modify policy settings after they have
already been set. Initial policy settings are always available immediately without delay.

Updates #12687

Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
Nick Khyl
2024-11-22 09:05:01 -06:00
committed by Nick Khyl
parent 462e1fc503
commit 8e5cfbe4ab
3 changed files with 15 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"
"tailscale.com/util/syspolicy/internal"
"tailscale.com/util/syspolicy/internal/loggerx"
"tailscale.com/util/syspolicy/setting"
@@ -447,3 +448,9 @@ func (p *Policy) Close() {
go p.closeInternal()
}
}
func setForTest[T any](tb internal.TB, target *T, newValue T) {
oldValue := *target
tb.Cleanup(func() { *target = oldValue })
*target = newValue
}