Skip to content

Commit b778c77

Browse files
vault e2e: 11% test speedup by replacing fixed allowlist sleeps with on-demand retry (#21707)
vault e2e: replace fixed allowlist sleep with on-demand retry Remove the 6-second time.Sleep after every allowlistRequest() call (14 calls × 6s = 84s of forced sleep per test run). Instead, add retry logic in sendVaultRequestToGateway() that detects gateway-level "request not allowlisted" rejections and retries every 2s up to 7 times. Node-level rejections (where the gateway already consumed the request) are correctly distinguished and not retried. Measured improvement: total test time 500s → 446s (-11%).
1 parent 9ab4baa commit b778c77

2 files changed

Lines changed: 49 additions & 13 deletions

File tree

system-tests/tests/smoke/cre/v2_vault_don_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ func allowlistRequest(t *testing.T, owner string, request jsonrpc.Request[json.R
603603
require.NoError(t, err, "failed to allowlist request")
604604

605605
framework.L.Info().Msgf("Allowlisting request digest at contract %s, for owner: %s, digestHexStr: %s", wfRegistryContract.Address().Hex(), owner, requestDigest)
606-
time.Sleep(6 * time.Second) // allowlist syncer polls every 5s; one tick + margin
607606
allowedList, err := wfRegistryContract.GetAllowlistedRequests(&bind.CallOpts{}, big.NewInt(0), big.NewInt(100))
608607
require.NoError(t, err, "failed to validate allowlisted request")
609608
for _, req := range allowedList {

system-tests/tests/smoke/cre/v2_vault_don_test_helpers.go

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"io"
77
"net/http"
8+
"strings"
89
"testing"
910
"time"
1011

@@ -56,20 +57,56 @@ func FetchVaultPublicKey(t *testing.T, gatewayURL string) (publicKey string) {
5657
}
5758

5859
func sendVaultRequestToGateway(t *testing.T, gatewayURL string, requestBody []byte) (statusCode int, body []byte) {
60+
const maxRetries = 7
61+
const retryInterval = 2 * time.Second
62+
5963
framework.L.Info().Msgf("Request Body: %s", string(requestBody))
60-
req, err := http.NewRequestWithContext(t.Context(), "POST", gatewayURL, bytes.NewBuffer(requestBody))
61-
require.NoError(t, err, "failed to create request")
6264

63-
req.Header.Set("Content-Type", "application/json")
64-
req.Header.Set("Accept", "application/json")
65+
for attempt := range maxRetries + 1 {
66+
req, err := http.NewRequestWithContext(t.Context(), "POST", gatewayURL, bytes.NewBuffer(requestBody))
67+
require.NoError(t, err, "failed to create request")
68+
69+
req.Header.Set("Content-Type", "application/json")
70+
req.Header.Set("Accept", "application/json")
71+
72+
client := &http.Client{}
73+
resp, err := client.Do(req)
74+
require.NoError(t, err, "failed to execute request")
6575

66-
client := &http.Client{}
67-
resp, err := client.Do(req)
68-
require.NoError(t, err, "failed to execute request")
69-
defer resp.Body.Close()
76+
body, err = io.ReadAll(resp.Body)
77+
resp.Body.Close()
78+
require.NoError(t, err, "failed to read http response body")
79+
statusCode = resp.StatusCode
7080

71-
body, err = io.ReadAll(resp.Body)
72-
require.NoError(t, err, "failed to read http response body")
73-
framework.L.Info().Msgf("HTTP Response Body: %s", string(body))
74-
return resp.StatusCode, body
81+
framework.L.Info().Msgf("HTTP Response Body: %s", string(body))
82+
83+
if !isGatewayNotAllowlistedError(body) {
84+
return statusCode, body
85+
}
86+
87+
if attempt < maxRetries {
88+
framework.L.Warn().Msgf("Request not yet allowlisted, retrying in %s (attempt %d/%d)...", retryInterval, attempt+1, maxRetries)
89+
time.Sleep(retryInterval)
90+
}
91+
}
92+
93+
return statusCode, body
94+
}
95+
96+
// isGatewayNotAllowlistedError checks whether the response is a gateway-level
97+
// "request not allowlisted" rejection (method is empty, error code -32600).
98+
// Node-level rejections (method is set, code -32603) have a different format
99+
// and must not be retried because the gateway has already consumed the request.
100+
func isGatewayNotAllowlistedError(body []byte) bool {
101+
var resp struct {
102+
Method string `json:"method"`
103+
Error *struct {
104+
Message string `json:"message"`
105+
} `json:"error"`
106+
}
107+
if json.Unmarshal(body, &resp) != nil {
108+
return false
109+
}
110+
return resp.Method == "" && resp.Error != nil &&
111+
strings.Contains(resp.Error.Message, "request not allowlisted")
75112
}

0 commit comments

Comments
 (0)