mirror of
https://github.com/minio/minio.git
synced 2025-11-09 13:39:46 -05:00
tests: Fix rare test crash (#4175)
Fix rare test crash by improving the randomness logic.
This commit is contained in:
committed by
Harshavardhana
parent
e5b2e25caf
commit
9b58a669e5
@@ -1833,25 +1833,23 @@ func (s *TestSuiteCommon) TestGetPartialObjectMisAligned(c *C) {
|
||||
c.Assert(response.StatusCode, Equals, http.StatusOK)
|
||||
|
||||
var buffer bytes.Buffer
|
||||
line := `1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
|
||||
1234567890,1234567890,1234567890,123`
|
||||
|
||||
rand.Seed(UTCNow().UnixNano())
|
||||
// Create a misalgined data.
|
||||
for i := 0; i < 13*rand.Intn(1<<16); i++ {
|
||||
buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line[:rand.Intn(1<<8)]))
|
||||
// data to be written into buffer.
|
||||
data := "1234567890"
|
||||
// seed the random number generator once.
|
||||
rand.Seed(3)
|
||||
// generate a random number between 13 and 200.
|
||||
randInt := getRandomRange(13, 200, -1)
|
||||
// write into buffer till length of the buffer is greater than the generated random number.
|
||||
for i := 0; i <= randInt; i += 10 {
|
||||
buffer.WriteString(data)
|
||||
}
|
||||
putContent := buffer.String()
|
||||
buf := bytes.NewReader([]byte(putContent))
|
||||
|
||||
// String content which is used for put object range test.
|
||||
putBytes := buffer.Bytes()
|
||||
putBytes = putBytes[:randInt]
|
||||
// randomize the order of bytes in the byte array and create a reader.
|
||||
putBytes = randomizeBytes(putBytes, -1)
|
||||
buf := bytes.NewReader(putBytes)
|
||||
putContent := string(putBytes)
|
||||
objectName := "test-big-file"
|
||||
// HTTP request to upload the object.
|
||||
request, err = newTestSignedRequest("PUT", getPutObjectURL(s.endPoint, bucketName, objectName),
|
||||
@@ -1882,6 +1880,7 @@ func (s *TestSuiteCommon) TestGetPartialObjectMisAligned(c *C) {
|
||||
// request for last 7 bytes of the object.
|
||||
{"-7", putContent[len(putContent)-7:]},
|
||||
}
|
||||
|
||||
for _, t := range testCases {
|
||||
// HTTP request to download the object.
|
||||
request, err = newTestSignedRequest("GET", getGetObjectURL(s.endPoint, bucketName, objectName),
|
||||
|
||||
Reference in New Issue
Block a user