|
diff --git a/.evergreen/mongoproxy/cmd/mongoproxy/main.go b/.evergreen/mongoproxy/cmd/mongoproxy/main.go |
|
index e6fa32f..15c976a 100644 |
|
--- a/.evergreen/mongoproxy/cmd/mongoproxy/main.go |
|
+++ b/.evergreen/mongoproxy/cmd/mongoproxy/main.go |
|
@@ -14,6 +14,7 @@ func main() { |
|
targetURI := flag.String("target-uri", "", "upstream MongoDB URI, e.g. mongodb://localhost:27017 (default: library default)") |
|
caFile := flag.String("ca-file", "", "CA file for TLS connections (default: none)") |
|
keyFile := flag.String("key-file", "", "Key file for TLS connections (default: none)") |
|
+ delayMs := flag.Int64("delay-ms", 0, "constant delay in milliseconds added to every server response (default: 0)") |
|
|
|
flag.Parse() |
|
|
|
@@ -34,6 +35,9 @@ func main() { |
|
if *keyFile != "" { |
|
opts = append(opts, mongoproxy.WithKeyFile(*keyFile)) |
|
} |
|
+ if *delayMs > 0 { |
|
+ opts = append(opts, mongoproxy.WithDelayMs(*delayMs)) |
|
+ } |
|
|
|
// Start the proxy. |
|
if err := mongoproxy.ListenAndServe(opts...); err != nil { |
|
diff --git a/.evergreen/mongoproxy/options.go b/.evergreen/mongoproxy/options.go |
|
index 6bdca75..247c2cc 100644 |
|
--- a/.evergreen/mongoproxy/options.go |
|
+++ b/.evergreen/mongoproxy/options.go |
|
@@ -18,6 +18,7 @@ type Config struct { |
|
TargetURI string // URI of the target MongoDB server |
|
CAFile string // Optional CA file for TLS connections |
|
KeyFile string // Optional key file for TLS connections |
|
+ DelayMs int64 // Constant delay in milliseconds added to every server response |
|
} |
|
|
|
// Option defines a function type that modifies the Config. |
|
@@ -58,6 +59,13 @@ func WithKeyFile(keyFile string) Option { |
|
} |
|
} |
|
|
|
+// WithDelayMs sets a constant delay in milliseconds added to every server response. |
|
+func WithDelayMs(ms int64) Option { |
|
+ return func(cfg *Config) { |
|
+ cfg.DelayMs = ms |
|
+ } |
|
+} |
|
+ |
|
// resolveTarget chooses between plain host:port or parses a Mongo URI. |
|
// |
|
// TODO: Likely for the SRV solution to work we will need to perform hello |
|
diff --git a/.evergreen/mongoproxy/proxy.go b/.evergreen/mongoproxy/proxy.go |
|
index 5b2122e..77cc0c0 100644 |
|
--- a/.evergreen/mongoproxy/proxy.go |
|
+++ b/.evergreen/mongoproxy/proxy.go |
|
@@ -100,11 +100,11 @@ func ListenAndServe(opts ...Option) error { |
|
return fmt.Errorf("failed to accept connection: %v", err) |
|
} |
|
|
|
- go handleConnection(clientConn, targetConnInfo) |
|
+ go handleConnection(clientConn, targetConnInfo, cfg.DelayMs) |
|
} |
|
} |
|
|
|
-func handleConnection(clientConn net.Conn, targetConnInfo connInfo) { |
|
+func handleConnection(clientConn net.Conn, targetConnInfo connInfo, delayMs int64) { |
|
defer clientConn.Close() |
|
|
|
var serverConn net.Conn |
|
@@ -130,7 +130,7 @@ func handleConnection(clientConn net.Conn, targetConnInfo connInfo) { |
|
|
|
// proxy both directions |
|
go proxyClientToMongo(clientConn, serverConn) |
|
- proxyMongoToClient(serverConn, clientConn) |
|
+ proxyMongoToClient(serverConn, clientConn, delayMs) |
|
} |
|
|
|
// pendingMap tracks per-client pending test instructions. |
|
@@ -253,7 +253,7 @@ func readWireMessage(src io.Reader) ([]byte, error) { |
|
} |
|
|
|
// proxyMongoToClient waits for an instruction on a matching connection, applies it to that first reply, then continues. |
|
-func proxyMongoToClient(src net.Conn, dst net.Conn) { |
|
+func proxyMongoToClient(src net.Conn, dst net.Conn, delayMs int64) { |
|
for { |
|
// Read the next full wire message from MongoDB. |
|
raw, err := readWireMessage(src) |
|
@@ -261,6 +261,10 @@ func proxyMongoToClient(src net.Conn, dst net.Conn) { |
|
return |
|
} |
|
|
|
+ if delayMs > 0 { |
|
+ time.Sleep(time.Duration(delayMs) * time.Millisecond) |
|
+ } |
|
+ |
|
// Check if we have a proxyTest for this dst. |
|
instr := pendingMap.Take(dst) |
|
if instr == nil { |
|
diff --git a/.evergreen/start-mongoproxy.sh b/.evergreen/start-mongoproxy.sh |
|
index 68326d2..14c4533 100755 |
|
--- a/.evergreen/start-mongoproxy.sh |
|
+++ b/.evergreen/start-mongoproxy.sh |
|
@@ -65,6 +65,11 @@ echo "Starting mongoproxy at ${MONGODB_URI}..." |
|
# Build the proxy command |
|
CMD=("./bin/mongoproxy" "--target-uri" "$MONGODB_URI") |
|
|
|
+# Optional constant response delay. |
|
+if [[ -n "${PROXY_DELAY_MS:-}" ]]; then |
|
+ CMD+=("--delay-ms" "$PROXY_DELAY_MS") |
|
+fi |
|
+ |
|
# only if SSL exactly equals "ssl", inject certs |
|
if [ "${SSL:-}" = "ssl" ]; then |
|
CMD+=( |