Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit b9740e3

Browse files
committed
increase test wait to 1m, remove sleeps from tests, add prebuffering of test data
1 parent fd523fc commit b9740e3

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ build:
5858

5959
unit-no-verify:
6060
@echo "go test SDK and vendor packages"
61-
go test -timeout 20s -v -count=1 -tags ${UNIT_TEST_TAGS} ${SDK_ALL_PKGS}
61+
go test -timeout 1m -v -count=1 -tags ${UNIT_TEST_TAGS} ${SDK_ALL_PKGS}
6262

6363
unit: verify build unit-no-verify
6464

6565
unit-with-race-cover: verify build
6666
@echo "go test SDK and vendor packages"
67-
go test -timeout 20s -v -count=1 -tags ${UNIT_TEST_TAGS} -race -cpu=1,2,4 ${SDK_ALL_PKGS}
67+
go test -timeout 1m -v -count=1 -tags ${UNIT_TEST_TAGS} -race -cpu=1,2,4 ${SDK_ALL_PKGS}
6868

6969
unit-old-go-race-cover:
7070
@echo "go test SDK only packages for old Go versions"
71-
go test -timeout 20s -v -count=1 -race -cpu=1,2,4 ${SDK_COMPA_PKGS}
71+
go test -timeout 1m -v -count=1 -race -cpu=1,2,4 ${SDK_COMPA_PKGS}
7272

7373
ci-test: generate unit-with-race-cover ci-test-generate-validate
7474

aws/credentials/credentials_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package credentials
22

33
import (
44
"math/rand"
5+
"sync"
56
"testing"
67
"time"
78

@@ -107,17 +108,20 @@ func TestCredentialsIsExpired_Race(t *testing.T) {
107108
creds := NewChainCredentials([]Provider{&MockProvider{}})
108109

109110
starter := make(chan struct{})
111+
var wg sync.WaitGroup
112+
wg.Add(10)
110113
for i := 0; i < 10; i++ {
111114
go func() {
115+
defer wg.Done()
112116
<-starter
113-
for {
117+
for i := 0; i < 100; i++ {
114118
creds.IsExpired()
115119
}
116120
}()
117121
}
118122
close(starter)
119123

120-
time.Sleep(10 * time.Second)
124+
wg.Wait()
121125
}
122126

123127
func TestCredentialsExpiresAt_NoExpirer(t *testing.T) {

awstesting/unit/unit.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
package unit
33

44
import (
5+
"time"
6+
57
"github.com/aws/aws-sdk-go/aws"
68
"github.com/aws/aws-sdk-go/aws/credentials"
79
"github.com/aws/aws-sdk-go/aws/session"
810
)
911

1012
// Session is a shared session for unit tests to use.
11-
var Session = session.Must(session.NewSession(aws.NewConfig().
12-
WithCredentials(credentials.NewStaticCredentials("AKID", "SECRET", "SESSION")).
13-
WithRegion("mock-region")))
13+
var Session = session.Must(session.NewSession(&aws.Config{
14+
Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
15+
Region: aws.String("mock-region"),
16+
SleepDelay: func(time.Duration) {},
17+
}))

service/s3/s3manager/download_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func dlLoggingSvcNoChunk(data []byte) (*s3.S3, *[]string) {
8888
func dlLoggingSvcNoContentRangeLength(data []byte, states []int) (*s3.S3, *[]string) {
8989
var m sync.Mutex
9090
names := []string{}
91-
var index int = 0
91+
var index int
9292

9393
svc := s3.New(unit.Session)
9494
svc.Handlers.Send.Clear()
@@ -113,7 +113,7 @@ func dlLoggingSvcContentRangeTotalAny(data []byte, states []int) (*s3.S3, *[]str
113113
var m sync.Mutex
114114
names := []string{}
115115
ranges := []string{}
116-
var index int = 0
116+
var index int
117117

118118
svc := s3.New(unit.Session)
119119
svc.Handlers.Send.Clear()
@@ -159,7 +159,7 @@ func dlLoggingSvcContentRangeTotalAny(data []byte, states []int) (*s3.S3, *[]str
159159
func dlLoggingSvcWithErrReader(cases []testErrReader) (*s3.S3, *[]string) {
160160
var m sync.Mutex
161161
names := []string{}
162-
var index int = 0
162+
var index int
163163

164164
svc := s3.New(unit.Session, &aws.Config{
165165
MaxRetries: aws.Int(len(cases) - 1),
@@ -193,7 +193,8 @@ func TestDownloadOrder(t *testing.T) {
193193
d := s3manager.NewDownloaderWithClient(s, func(d *s3manager.Downloader) {
194194
d.Concurrency = 1
195195
})
196-
w := &aws.WriteAtBuffer{}
196+
197+
w := aws.NewWriteAtBuffer(make([]byte, len(buf12MB)))
197198
n, err := d.Download(w, &s3.GetObjectInput{
198199
Bucket: aws.String("bucket"),
199200
Key: aws.String("key"),
@@ -215,14 +216,6 @@ func TestDownloadOrder(t *testing.T) {
215216
if e, a := expectRngs, *ranges; !reflect.DeepEqual(e, a) {
216217
t.Errorf("expect %v ranges, got %v", e, a)
217218
}
218-
219-
count := 0
220-
for _, b := range w.Bytes() {
221-
count += int(b)
222-
}
223-
if count != 0 {
224-
t.Errorf("expect 0 count, got %d", count)
225-
}
226219
}
227220

228221
func TestDownloadZero(t *testing.T) {

0 commit comments

Comments
 (0)