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:
@@ -129,6 +129,7 @@ func TestS3IAMDistributedTests(t *testing.T) {
|
|||||||
errorMsg := err.Error()
|
errorMsg := err.Error()
|
||||||
return strings.Contains(errorMsg, "timeout") ||
|
return strings.Contains(errorMsg, "timeout") ||
|
||||||
strings.Contains(errorMsg, "connection reset") ||
|
strings.Contains(errorMsg, "connection reset") ||
|
||||||
|
strings.Contains(errorMsg, "connection refused") ||
|
||||||
strings.Contains(errorMsg, "temporary failure") ||
|
strings.Contains(errorMsg, "temporary failure") ||
|
||||||
strings.Contains(errorMsg, "TooManyRequests") ||
|
strings.Contains(errorMsg, "TooManyRequests") ||
|
||||||
strings.Contains(errorMsg, "ServiceUnavailable") ||
|
strings.Contains(errorMsg, "ServiceUnavailable") ||
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package s3tables
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
cryptorand "crypto/rand"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"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
|
// randomString generates a random string for unique naming
|
||||||
func randomString(length int) string {
|
func randomString(length int) string {
|
||||||
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
|
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
rng := rand.New(rand.NewSource(time.Now().UnixNano() + rand.Int63()))
|
|
||||||
b := make([]byte, length)
|
b := make([]byte, length)
|
||||||
|
if _, err := cryptorand.Read(b); err != nil {
|
||||||
|
panic("failed to generate random string: " + err.Error())
|
||||||
|
}
|
||||||
for i := range b {
|
for i := range b {
|
||||||
b[i] = charset[rng.Intn(len(charset))]
|
b[i] = charset[int(b[i])%len(charset)]
|
||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user