Skip to content

Commit

Permalink
Close channels.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodauria committed Jul 14, 2021
1 parent 345193e commit 1965aa7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func Run(ctx context.Context, conn websocketx.Conn, ch chan<- spec.Measurement)
ctx, cancel := context.WithTimeout(ctx, params.UploadTimeout)
defer cancel()
errCh := make(chan error)
defer close(errCh)
go readcounterflow(ctx, conn, ch, errCh)
start := time.Now()
prev := start
Expand Down
10 changes: 7 additions & 3 deletions internal/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestReadMessageError(t *testing.T) {
}
ch := make(chan spec.Measurement, 128)
errCh := make(chan error)
defer close(errCh)
go readcounterflow(context.Background(), &conn, ch, errCh)
err := <-errCh
if err != mockedErr {
Expand All @@ -73,6 +74,7 @@ func TestReadNonTextMessageError(t *testing.T) {
}
ch := make(chan spec.Measurement, 128)
errCh := make(chan error)
defer close(errCh)
go readcounterflow(context.Background(), &conn, ch, errCh)
err := <-errCh
if err != errNonTextMessage {
Expand All @@ -87,6 +89,7 @@ func TestReadNonJSONError(t *testing.T) {
}
ch := make(chan spec.Measurement, 128)
errCh := make(chan error)
defer close(errCh)
go readcounterflow(context.Background(), &conn, ch, errCh)
err := <-errCh
var syntaxError *json.SyntaxError
Expand All @@ -109,9 +112,10 @@ func TestReadGoodMessage(t *testing.T) {
cancel()
}
}()
errs := make(chan error)
go readcounterflow(ctx, &conn, ch, errs)
err := <-errs
errCh := make(chan error)
defer close(errCh)
go readcounterflow(ctx, &conn, ch, errCh)
err := <-errCh
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 1965aa7

Please sign in to comment.