func (l *TransactionalLatencyInjector) Transaction(ctx context.Context, txns []*TxnEntry) error {
	l.addLatency()
	return l.Transactional.Transaction(ctx, txns)
}
Transaction is a latent transaction request
package physical
import (
	"context"
	"math/rand"
	"time"
	log "github.com/hashicorp/go-hclog"
)
const (
	DefaultJitterPercent = 20
)
type LatencyInjector struct {
	backend       Backend
	latency       time.Duration
	jitterPercent int
	random        *rand.Rand
}
type TransactionalLatencyInjector struct {
	*LatencyInjector
	Transactional
}
var _ Backend = (*LatencyInjector)(nil)
var _ Transactional = (*TransactionalLatencyInjector)(nil)
func NewLatencyInjector(b Backend, latency time.Duration, jitter int, logger log.Logger) *LatencyInjector {
	if jitter < 0 || jitter > 100 {
		jitter = DefaultJitterPercent
	}
	logger.Info("creating latency injector")
	return &LatencyInjector{
		backend:       b,
		latency:       latency,
		jitterPercent: jitter,
		random:        rand.New(rand.NewSource(int64(time.Now().Nanosecond()))),
	}
}
func NewTransactionalLatencyInjector(b Backend, latency time.Duration, jitter int, logger log.Logger) *TransactionalLatencyInjector {
	return &TransactionalLatencyInjector{
		LatencyInjector: NewLatencyInjector(b, latency, jitter, logger),
		Transactional:   b.(Transactional),
	}
}
func (l *LatencyInjector) addLatency() {
	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)
}
func (l *LatencyInjector) Put(ctx context.Context, entry *Entry) error {
	l.addLatency()
	return l.backend.Put(ctx, entry)
}
func (l *LatencyInjector) Get(ctx context.Context, key string) (*Entry, error) {
	l.addLatency()
	return l.backend.Get(ctx, key)
}
func (l *LatencyInjector) Delete(ctx context.Context, key string) error {
	l.addLatency()
	return l.backend.Delete(ctx, key)
}
func (l *LatencyInjector) List(ctx context.Context, prefix string) ([]string, error) {
	l.addLatency()
	return l.backend.List(ctx, prefix)
}