Port some changes (#5518)
This commit is contained in:
parent
799e5d6bde
commit
f52cd4950f
|
@ -35,7 +35,7 @@ var _ Transactional = (*TransactionalErrorInjector)(nil)
|
|||
// NewErrorInjector returns a wrapped physical backend to inject error
|
||||
func NewErrorInjector(b Backend, errorPercent int, logger log.Logger) *ErrorInjector {
|
||||
if errorPercent < 0 || errorPercent > 100 {
|
||||
errorPercent = DefaultJitterPercent
|
||||
errorPercent = DefaultErrorPercent
|
||||
}
|
||||
logger.Info("creating error injector")
|
||||
|
||||
|
|
|
@ -57,9 +57,12 @@ func NewTransactionalLatencyInjector(b Backend, latency time.Duration, jitter in
|
|||
|
||||
func (l *LatencyInjector) addLatency() {
|
||||
// Calculate a value between 1 +- jitter%
|
||||
min := 100 - l.jitterPercent
|
||||
max := 100 + l.jitterPercent
|
||||
percent := l.random.Intn(max-min) + min
|
||||
percent := 100
|
||||
if l.jitterPercent > 0 {
|
||||
min := 100 - l.jitterPercent
|
||||
max := 100 + l.jitterPercent
|
||||
percent = l.random.Intn(max-min) + min
|
||||
}
|
||||
latencyDuration := time.Duration(int(l.latency) * percent / 100)
|
||||
time.Sleep(latencyDuration)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue