Port some changes (#5518)

This commit is contained in:
Brian Kassouf 2018-10-15 14:06:45 -07:00 committed by GitHub
parent 799e5d6bde
commit f52cd4950f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -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")

View File

@ -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)
}