s3tables: enhance test robustness and resilience

Updated random string generation to use crypto/rand in s3tables tests.
Increased resilience of IAM distributed tests by adding "connection refused"
to retryable errors.
This commit is contained in:
Chris Lu
2026-01-28 13:25:32 -08:00
parent 2b2ff008cd
commit dfdace9a13
2 changed files with 6 additions and 3 deletions

View File

@@ -129,6 +129,7 @@ func TestS3IAMDistributedTests(t *testing.T) {
errorMsg := err.Error()
return strings.Contains(errorMsg, "timeout") ||
strings.Contains(errorMsg, "connection reset") ||
strings.Contains(errorMsg, "connection refused") ||
strings.Contains(errorMsg, "temporary failure") ||
strings.Contains(errorMsg, "TooManyRequests") ||
strings.Contains(errorMsg, "ServiceUnavailable") ||

View File

@@ -3,7 +3,6 @@ package s3tables
import (
"context"
"fmt"
"math/rand"
"net"
"net/http"
"os"
@@ -12,6 +11,7 @@ import (
"testing"
"time"
cryptorand "crypto/rand"
"sync"
"github.com/stretchr/testify/assert"
@@ -495,10 +495,12 @@ func waitForS3Ready(endpoint string, timeout time.Duration) error {
// randomString generates a random string for unique naming
func randomString(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
rng := rand.New(rand.NewSource(time.Now().UnixNano() + rand.Int63()))
b := make([]byte, length)
if _, err := cryptorand.Read(b); err != nil {
panic("failed to generate random string: " + err.Error())
}
for i := range b {
b[i] = charset[rng.Intn(len(charset))]
b[i] = charset[int(b[i])%len(charset)]
}
return string(b)
}