mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-19 09:30:58 +00:00
types/lazy: re-init SyncValue during test cleanup if it wasn't set before SetForTest
Updates #12687 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -170,8 +170,8 @@ type TB interface {
|
||||
func (z *SyncValue[T]) SetForTest(tb TB, val T, err error) {
|
||||
tb.Helper()
|
||||
|
||||
z.once.Do(func() {})
|
||||
oldErr, oldVal := z.err.Load(), z.v
|
||||
z.once.Do(func() {})
|
||||
|
||||
z.v = val
|
||||
if err != nil {
|
||||
@@ -181,7 +181,11 @@ func (z *SyncValue[T]) SetForTest(tb TB, val T, err error) {
|
||||
}
|
||||
|
||||
tb.Cleanup(func() {
|
||||
z.v = oldVal
|
||||
z.err.Store(oldErr)
|
||||
if oldErr == nil {
|
||||
*z = SyncValue[T]{}
|
||||
} else {
|
||||
z.v = oldVal
|
||||
z.err.Store(oldErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user