Skip to content
cloudemu
Features

Documentation

Latency Simulation

Add delays to test timeout handling and performance

Add fixed delays per provider or per service to test timeouts and context cancellation.

config.WithLatency(800 * time.Millisecond)

default · ~10msconfig.WithLatency(800ms)

Provider-level latency#

Add latency to all operations on a provider:

aws := cloudemu.NewAWS(
    config.WithLatency(50 * time.Millisecond),
)

Service-level latency#

Add latency to specific services using the portable API:

bucket := storage.NewBucket(aws.S3,
    storage.WithLatency(100 * time.Millisecond),
)

Use cases#

  • Test timeout handling — verify your code handles slow responses correctly
  • Test context cancellation — ensure operations respect context.WithTimeout
  • Performance testing — measure how your code behaves at different latencies
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()

// This will succeed (100ms < 200ms timeout)
bucket.PutObject(ctx, "bucket", "key", data, "text/plain", nil)

// With higher latency, it would timeout
slowBucket := storage.NewBucket(aws.S3,
    storage.WithLatency(500 * time.Millisecond),
)

err := slowBucket.PutObject(ctx, "bucket", "key2", data, "text/plain", nil)
// err == context.DeadlineExceeded

On this page

On this page