Skip to content

Commit

Permalink
fix test failure TestUploadDownloadOneFileRequireCompressStream
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jl committed Dec 5, 2024
1 parent b963ef0 commit a841c0e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
10 changes: 3 additions & 7 deletions connection_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,9 @@ func getFileStream(ctx context.Context) (*bytes.Buffer, error) {

// read a small amount of data to check if file stream will be used
buf := make([]byte, defaultStringBufferSize)
for {
_, err := r.Read(buf)
if err != nil {
return nil, err
} else {
break
}
_, err := r.Read(buf)
if err != nil {
return nil, err
}
return bytes.NewBuffer(buf), nil
}
Expand Down
2 changes: 1 addition & 1 deletion file_transfer_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ func (sfa *snowflakeFileTransferAgent) uploadOneFile(meta *fileMetadata) (*fileM
}

if meta.srcStream != nil {
meta.sha256Digest, meta.uploadSize, err = fileUtil.getDigestAndSizeForStream(&meta.realSrcStream, &meta.srcStream, sfa.ctx)
meta.sha256Digest, meta.uploadSize, err = fileUtil.getDigestAndSizeForStream(sfa.ctx, &meta.realSrcStream, &meta.srcStream)
} else {
meta.sha256Digest, meta.uploadSize, err = fileUtil.getDigestAndSizeForFile(meta.realSrcFileName)
}
Expand Down
7 changes: 4 additions & 3 deletions file_transfer_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/s3"
"io"
"net/url"
"os"
Expand All @@ -18,6 +17,8 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/service/s3"

"github.com/aws/smithy-go"
)

Expand Down Expand Up @@ -980,8 +981,8 @@ func testUploadDownloadOneFile(t *testing.T, isStream bool) {

if isStream {
fileStream, _ := os.Open(uploadFile)
ctx := WithFileStream(context.Background(), fileStream)
uploadMeta.srcStream, err = getFileStream(ctx)
sfa.ctx = WithFileStream(context.Background(), fileStream)
uploadMeta.srcStream, err = getFileStream(sfa.ctx)
assertNilF(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (util *snowflakeFileUtil) compressFileWithGzip(fileName string, tmpDir stri
return gzipFileName, stat.Size(), err
}

func (util *snowflakeFileUtil) getDigestAndSizeForStream(realSrcStream **bytes.Buffer, srcStream **bytes.Buffer, ctx context.Context) (string, int64, error) {
func (util *snowflakeFileUtil) getDigestAndSizeForStream(ctx context.Context, realSrcStream **bytes.Buffer, srcStream **bytes.Buffer) (string, int64, error) {
var r io.Reader
var stream **bytes.Buffer
if realSrcStream != nil {
Expand Down

0 comments on commit a841c0e

Please sign in to comment.