1
0
Fork 0

Better waiting for upload tests to finish

master
Philip O'Toole 1 year ago
parent 3ca9f23225
commit 7087fe6c45

@ -49,6 +49,7 @@ func Test_UploaderSingleUpload(t *testing.T) {
go uploader.Start(ctx, nil) go uploader.Start(ctx, nil)
wg.Wait() wg.Wait()
cancel() cancel()
<-ctx.Done()
if exp, got := string(uploadedData), "my upload data"; exp != got { if exp, got := string(uploadedData), "my upload data"; exp != got {
t.Errorf("expected uploadedData to be %s, got %s", exp, got) t.Errorf("expected uploadedData to be %s, got %s", exp, got)
@ -92,6 +93,7 @@ func Test_UploaderDoubleUpload(t *testing.T) {
go uploader.Start(ctx, nil) go uploader.Start(ctx, nil)
wg.Wait() wg.Wait()
cancel() cancel()
<-ctx.Done()
if exp, got := string(uploadedData), "my upload data"; exp != got { if exp, got := string(uploadedData), "my upload data"; exp != got {
t.Errorf("expected uploadedData to be %s, got %s", exp, got) t.Errorf("expected uploadedData to be %s, got %s", exp, got)
@ -141,6 +143,7 @@ func Test_UploaderFailThenOK(t *testing.T) {
go uploader.Start(ctx, nil) go uploader.Start(ctx, nil)
wg.Wait() wg.Wait()
cancel() cancel()
<-ctx.Done()
if exp, got := string(uploadedData), "my upload data"; exp != got { if exp, got := string(uploadedData), "my upload data"; exp != got {
t.Errorf("expected uploadedData to be %s, got %s", exp, got) t.Errorf("expected uploadedData to be %s, got %s", exp, got)
@ -188,6 +191,7 @@ func Test_UploaderOKThenFail(t *testing.T) {
go uploader.Start(ctx, nil) go uploader.Start(ctx, nil)
wg.Wait() wg.Wait()
cancel() cancel()
<-ctx.Done()
if exp, got := string(uploadedData), "my upload data"; exp != got { if exp, got := string(uploadedData), "my upload data"; exp != got {
t.Errorf("expected uploadedData to be %s, got %s", exp, got) t.Errorf("expected uploadedData to be %s, got %s", exp, got)
@ -210,6 +214,7 @@ func Test_UploaderContextCancellation(t *testing.T) {
go uploader.Start(ctx, nil) go uploader.Start(ctx, nil)
<-ctx.Done() <-ctx.Done()
cancel() cancel()
<-ctx.Done()
if exp, got := int32(0), atomic.LoadInt32(&uploadCount); exp != got { if exp, got := int32(0), atomic.LoadInt32(&uploadCount); exp != got {
t.Errorf("expected uploadCount to be %d, got %d", exp, got) t.Errorf("expected uploadCount to be %d, got %d", exp, got)

Loading…
Cancel
Save