github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/fleetspeak/src/server/sertesting/retry.go (about) 1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sertesting 16 17 import ( 18 "time" 19 20 "github.com/google/fleetspeak/fleetspeak/src/server/internal/ftime" 21 ) 22 23 // SetClientRetryTime changes db.ClientRetryTime method used by datastores to 24 // decide when to retry requests to clients. It returns a closure which returns 25 // the system to the previous state. 26 // 27 // This function and the returned closure are not thread safe. In particular, they should 28 // be called at the start and end of tests when no Fleetspeak component is started. 29 func SetClientRetryTime(f func() time.Time) func() { 30 op := ftime.ClientRetryTime 31 ftime.ClientRetryTime = f 32 return func() { 33 ftime.ClientRetryTime = op 34 } 35 } 36 37 // SetServerRetryTime changes the db.ServerRetryTime used by the Fleetspeak 38 // server to decide when to retry requests to clients. It returns a closure 39 // which returns the system to the previous state. 40 // 41 // This function and the returned closure are not thread safe. In particular, they should 42 // be called at the start and end of tests when no Fleetspeak component is started. 43 func SetServerRetryTime(f func(uint32) time.Time) func() { 44 op := ftime.ServerRetryTime 45 ftime.ServerRetryTime = f 46 return func() { 47 ftime.ServerRetryTime = op 48 } 49 }