From 59a877a67a476fa8583c835d38e8fed418602701 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 15 Jan 2026 19:00:48 +0100 Subject: [PATCH] test(gateway): add MaxRequestDuration integration test verifies config is wired correctly and 504 is returned when exceeded --- test/cli/gateway_limits_test.go | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/cli/gateway_limits_test.go b/test/cli/gateway_limits_test.go index 990eabb1a..3e3b8540a 100644 --- a/test/cli/gateway_limits_test.go +++ b/test/cli/gateway_limits_test.go @@ -58,6 +58,47 @@ func TestGatewayLimits(t *testing.T) { assert.Contains(t, resp.Body, "Unable to retrieve content within timeout period") }) + t.Run("MaxRequestDuration", func(t *testing.T) { + t.Parallel() + + // Create a node with a short max request duration + node := harness.NewT(t).NewNode().Init() + node.UpdateConfig(func(cfg *config.Config) { + // Set a short absolute deadline (500ms) for the entire request + cfg.Gateway.MaxRequestDuration = config.NewOptionalDuration(500 * time.Millisecond) + // Set retrieval timeout much longer so MaxRequestDuration fires first + cfg.Gateway.RetrievalTimeout = config.NewOptionalDuration(30 * time.Second) + }) + node.StartDaemon() + defer node.StopDaemon() + + // Add content that can be retrieved quickly + cid := node.IPFSAddStr("test content for max request duration") + + client := node.GatewayClient() + + // Fast request for local content should succeed (well within 500ms) + resp := client.Get("/ipfs/" + cid) + assert.Equal(t, http.StatusOK, resp.StatusCode) + assert.Equal(t, "test content for max request duration", resp.Body) + + // Request for non-existent content should timeout due to MaxRequestDuration + // This CID has no providers and will block during content routing + nonExistentCID := "bafkreif6lrhgz3fpiwypdk65qrqiey7svgpggruhbylrgv32l3izkqpsc4" + + // Create a client with a longer timeout than MaxRequestDuration + // to ensure we receive the gateway's 504 response + clientWithTimeout := &harness.HTTPClient{ + Client: &http.Client{ + Timeout: 5 * time.Second, + }, + BaseURL: client.BaseURL, + } + + resp = clientWithTimeout.Get("/ipfs/" + nonExistentCID) + assert.Equal(t, http.StatusGatewayTimeout, resp.StatusCode, "Expected 504 when request exceeds MaxRequestDuration") + }) + t.Run("MaxConcurrentRequests", func(t *testing.T) { t.Parallel()