mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
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:
parent
462e1fc503
commit
8e5cfbe4ab
@ -11,6 +11,7 @@
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tailscale.com/util/syspolicy/internal"
|
||||||
"tailscale.com/util/syspolicy/internal/loggerx"
|
"tailscale.com/util/syspolicy/internal/loggerx"
|
||||||
"tailscale.com/util/syspolicy/setting"
|
"tailscale.com/util/syspolicy/setting"
|
||||||
|
|
||||||
@ -447,3 +448,9 @@ func (p *Policy) Close() {
|
|||||||
go p.closeInternal()
|
go p.closeInternal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setForTest[T any](tb internal.TB, target *T, newValue T) {
|
||||||
|
oldValue := *target
|
||||||
|
tb.Cleanup(func() { *target = oldValue })
|
||||||
|
*target = newValue
|
||||||
|
}
|
||||||
|
@ -574,9 +574,6 @@ func TestPolicyChangeHasChanged(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestChangePolicySetting(t *testing.T) {
|
func TestChangePolicySetting(t *testing.T) {
|
||||||
setForTest(t, &policyReloadMinDelay, 100*time.Millisecond)
|
|
||||||
setForTest(t, &policyReloadMaxDelay, 500*time.Millisecond)
|
|
||||||
|
|
||||||
// Register policy settings used in this test.
|
// Register policy settings used in this test.
|
||||||
settingA := setting.NewDefinition("TestSettingA", setting.DeviceSetting, setting.StringValue)
|
settingA := setting.NewDefinition("TestSettingA", setting.DeviceSetting, setting.StringValue)
|
||||||
settingB := setting.NewDefinition("TestSettingB", setting.DeviceSetting, setting.StringValue)
|
settingB := setting.NewDefinition("TestSettingB", setting.DeviceSetting, setting.StringValue)
|
||||||
@ -589,6 +586,10 @@ func TestChangePolicySetting(t *testing.T) {
|
|||||||
if _, err := RegisterStoreForTest(t, "TestSource", setting.DeviceScope, store); err != nil {
|
if _, err := RegisterStoreForTest(t, "TestSource", setting.DeviceScope, store); err != nil {
|
||||||
t.Fatalf("Failed to register policy store: %v", err)
|
t.Fatalf("Failed to register policy store: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setForTest(t, &policyReloadMinDelay, 100*time.Millisecond)
|
||||||
|
setForTest(t, &policyReloadMaxDelay, 500*time.Millisecond)
|
||||||
|
|
||||||
policy, err := policyForTest(t, setting.DeviceScope)
|
policy, err := policyForTest(t, setting.DeviceScope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get effective policy: %v", err)
|
t.Fatalf("Failed to get effective policy: %v", err)
|
||||||
@ -978,9 +979,3 @@ func policyForTest(tb testing.TB, target setting.PolicyScope) (*Policy, error) {
|
|||||||
})
|
})
|
||||||
return policy, nil
|
return policy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setForTest[T any](tb testing.TB, target *T, newValue T) {
|
|
||||||
oldValue := *target
|
|
||||||
tb.Cleanup(func() { *target = oldValue })
|
|
||||||
*target = newValue
|
|
||||||
}
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"tailscale.com/util/syspolicy/internal"
|
"tailscale.com/util/syspolicy/internal"
|
||||||
"tailscale.com/util/syspolicy/setting"
|
"tailscale.com/util/syspolicy/setting"
|
||||||
@ -33,6 +34,9 @@ func RegisterStore(name string, scope setting.PolicyScope, store source.Store) (
|
|||||||
// RegisterStoreForTest is like [RegisterStore], but unregisters the store when
|
// RegisterStoreForTest is like [RegisterStore], but unregisters the store when
|
||||||
// tb and all its subtests complete.
|
// tb and all its subtests complete.
|
||||||
func RegisterStoreForTest(tb internal.TB, name string, scope setting.PolicyScope, store source.Store) (*StoreRegistration, error) {
|
func RegisterStoreForTest(tb internal.TB, name string, scope setting.PolicyScope, store source.Store) (*StoreRegistration, error) {
|
||||||
|
setForTest(tb, &policyReloadMinDelay, 10*time.Millisecond)
|
||||||
|
setForTest(tb, &policyReloadMaxDelay, 500*time.Millisecond)
|
||||||
|
|
||||||
reg, err := RegisterStore(name, scope, store)
|
reg, err := RegisterStore(name, scope, store)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tb.Cleanup(func() {
|
tb.Cleanup(func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user