Browse Source

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.
pull/8147/head
Chris Lu 3 days ago
parent
commit
dfdace9a13
  1. 1
      test/s3/iam/s3_iam_distributed_test.go
  2. 8
      test/s3tables/s3tables_integration_test.go

1
test/s3/iam/s3_iam_distributed_test.go

@ -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") ||

8
test/s3tables/s3tables_integration_test.go

@ -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)
}
Loading…
Cancel
Save