Skip to content

Commit

Permalink
tests: Reduce context timeout to avoid false positives
Browse files Browse the repository at this point in the history
context timeout tests had long timeouts leading
to false positives in some cases when functional
tests are run against faster disks.

Reduce them such that the possibility of this
would never occur in future usage.

Fixes #880
  • Loading branch information
harshavardhana authored and minio-trusted committed Nov 19, 2017
1 parent 9a9f8cb commit 7848c69
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion api-compose-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (s *SourceInfo) getProps(c Client) (size int64, etag string, userMeta map[s
for k, v := range s.decryptKey.getSSEHeaders(false) {
opts.Set(k, v)
}
objInfo, err = c.statObject(s.bucket, s.object, opts)
objInfo, err = c.statObject(context.Background(), s.bucket, s.object, opts)
if err != nil {
err = ErrInvalidArgument(fmt.Sprintf("Could not stat object - %s/%s: %v", s.bucket, s.object, err))
} else {
Expand Down
4 changes: 2 additions & 2 deletions api-get-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (c Client) getObjectWithContext(ctx context.Context, bucketName, objectName
} else {
// First request is a Stat or Seek call.
// Only need to run a StatObject until an actual Read or ReadAt request comes through.
objectInfo, err = c.statObject(bucketName, objectName, StatObjectOptions{opts})
objectInfo, err = c.statObject(ctx, bucketName, objectName, StatObjectOptions{opts})
if err != nil {
resCh <- getResponse{
Error: err,
Expand All @@ -145,7 +145,7 @@ func (c Client) getObjectWithContext(ctx context.Context, bucketName, objectName
if etag != "" {
opts.SetMatchETag(etag)
}
objectInfo, err := c.statObject(bucketName, objectName, StatObjectOptions{opts})
objectInfo, err := c.statObject(ctx, bucketName, objectName, StatObjectOptions{opts})
if err != nil {
resCh <- getResponse{
Error: err,
Expand Down
6 changes: 3 additions & 3 deletions api-stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func (c Client) StatObject(bucketName, objectName string, opts StatObjectOptions
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return ObjectInfo{}, err
}
return c.statObject(bucketName, objectName, opts)
return c.statObject(context.Background(), bucketName, objectName, opts)
}

// Lower level API for statObject supporting pre-conditions and range headers.
func (c Client) statObject(bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) {
func (c Client) statObject(ctx context.Context, bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return ObjectInfo{}, err
Expand All @@ -104,7 +104,7 @@ func (c Client) statObject(bucketName, objectName string, opts StatObjectOptions
}

// Execute HEAD on objectName.
resp, err := c.executeMethod(context.Background(), "HEAD", requestMetadata{
resp, err := c.executeMethod(ctx, "HEAD", requestMetadata{
bucketName: bucketName,
objectName: objectName,
contentSHA256Hex: emptySHA256Hex,
Expand Down
2 changes: 1 addition & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ func (c Core) GetObject(bucketName, objectName string, opts GetObjectOptions) (i
// StatObject is a lower level API implemented to support special
// conditions matching etag, modtime on a request.
func (c Core) StatObject(bucketName, objectName string, opts StatObjectOptions) (ObjectInfo, error) {
return c.statObject(bucketName, objectName, opts)
return c.statObject(context.Background(), bucketName, objectName, opts)
}
48 changes: 28 additions & 20 deletions functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ func testFPutObjectWithContext() {
// Set base object name
objectName := bucketName + "FPutObjectWithContext"
args["objectName"] = objectName
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
args["ctx"] = ctx
defer cancel()

Expand All @@ -1618,7 +1618,7 @@ func testFPutObjectWithContext() {
logError(function, args, startTime, "", "Request context cancellation failed", err)
return
}
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Minute)
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()
// Perform FPutObjectWithContext with a long timeout. Expect the put object to succeed
n, err := c.FPutObjectWithContext(ctx, bucketName, objectName+"-Longtimeout", fName, minio.PutObjectOptions{})
Expand Down Expand Up @@ -1720,7 +1720,7 @@ func testFPutObjectWithContextV2() {
objectName := bucketName + "FPutObjectWithContext"
args["objectName"] = objectName

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
args["ctx"] = ctx
defer cancel()

Expand All @@ -1730,7 +1730,7 @@ func testFPutObjectWithContextV2() {
logError(function, args, startTime, "", "FPutObjectWithContext with short timeout failed", err)
return
}
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Minute)
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()
// Perform FPutObjectWithContext with a long timeout. Expect the put object to succeed
n, err := c.FPutObjectWithContext(ctx, bucketName, objectName+"-Longtimeout", fName, minio.PutObjectOptions{})
Expand Down Expand Up @@ -1803,18 +1803,18 @@ func testPutObjectWithContext() {
objectName := fmt.Sprintf("test-file-%v", rand.Uint32())
args["objectName"] = objectName

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
args["ctx"] = ctx
args["opts"] = minio.PutObjectOptions{ContentType: "binary/octet-stream"}
defer cancel()

_, err = c.PutObjectWithContext(ctx, bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"})
if err != nil {
if err == nil {
logError(function, args, startTime, "", "PutObjectWithContext with short timeout failed", err)
return
}

ctx, cancel = context.WithTimeout(context.Background(), 3*time.Minute)
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
args["ctx"] = ctx

defer cancel()
Expand Down Expand Up @@ -6073,17 +6073,21 @@ func testGetObjectWithContext() {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
args["ctx"] = ctx
defer cancel()

// Read the data back
r, err := c.GetObjectWithContext(ctx, bucketName, objectName, minio.GetObjectOptions{})
if err != nil {
logError(function, args, startTime, "", "GetObjectWithContext failed - request timeout not honored", err)
logError(function, args, startTime, "", "GetObjectWithContext failed unexpectedly", err)
return
}
ctx, cancel = context.WithTimeout(context.Background(), 3*time.Minute)
if _, err = r.Stat(); err == nil {
logError(function, args, startTime, "", "GetObjectWithContext did not failure to due to cancellation upon short timeout", err)
return
}

ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
args["ctx"] = ctx
defer cancel()

Expand Down Expand Up @@ -6174,7 +6178,7 @@ func testFGetObjectWithContext() {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
args["ctx"] = ctx
defer cancel()

Expand All @@ -6186,7 +6190,7 @@ func testFGetObjectWithContext() {
logError(function, args, startTime, "", "FGetObjectWithContext with short timeout failed", err)
return
}
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()

// Read the data back
Expand Down Expand Up @@ -6265,7 +6269,7 @@ func testPutObjectWithContextV2() {
return
}

ctx, cancel = context.WithTimeout(context.Background(), 3*time.Minute)
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
args["ctx"] = ctx

defer cancel()
Expand Down Expand Up @@ -6342,17 +6346,21 @@ func testGetObjectWithContextV2() {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
args["ctx"] = ctx
defer cancel()

// Read the data back
r, err := c.GetObjectWithContext(ctx, bucketName, objectName, minio.GetObjectOptions{})
if err != nil {
logError(function, args, startTime, "", "GetObjectWithContext failed due to non-cancellation upon short timeout", err)
logError(function, args, startTime, "", "GetObjectWithContext failed unexpectedly", err)
return
}
if _, err = r.Stat(); err == nil {
logError(function, args, startTime, "", "GetObjectWithContext did not failure to due to cancellation upon short timeout", err)
return
}
ctx, cancel = context.WithTimeout(context.Background(), 3*time.Minute)

ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()

// Read the data back
Expand Down Expand Up @@ -6451,10 +6459,10 @@ func testFGetObjectWithContextV2() {
// Read the data back
err = c.FGetObjectWithContext(ctx, bucketName, objectName, fileName+"-f", minio.GetObjectOptions{})
if err == nil {
logError(function, args, startTime, "", "FGetObjectWithContext call with short request timeout failed", err)
logError(function, args, startTime, "", "FGetObjectWithContext call did not fail for short request timeout", err)
return
}
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()

// Read the data back
Expand Down

0 comments on commit 7848c69

Please sign in to comment.