Skip to content

Commit

Permalink
Cosmetic changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodauria committed Jul 13, 2021
1 parent 258c528 commit f5cd4aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions internal/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var errNonTextMessage = errors.New("Received non textual message")
// readcounterflow reads counter flow message. The error is typically ignored
// as this code runs in its own goroutine, yet it's useful for testing.
func readcounterflow(ctx context.Context, conn websocketx.Conn, ch chan<- spec.Measurement,
errors chan<- error) {
errCh chan<- error) {
conn.SetReadLimit(params.MaxMessageSize)
for ctx.Err() == nil {
// Implementation note: this guarantees that the websocket engine
Expand All @@ -50,25 +50,25 @@ func readcounterflow(ctx context.Context, conn websocketx.Conn, ch chan<- spec.M
// which the server is not sending us any messages.
err := conn.SetReadDeadline(time.Now().Add(params.UploadTimeout))
if err != nil {
errors <- err
errCh <- err
}
mtype, mdata, err := conn.ReadMessage()
if err != nil {
errors <- err
errCh <- err
}
if mtype != websocket.TextMessage {
errors <- errNonTextMessage
errCh <- errNonTextMessage
}
var measurement spec.Measurement
if err := json.Unmarshal(mdata, &measurement); err != nil {
errors <- err
errCh <- err
}
measurement.Origin = spec.OriginServer
measurement.Test = spec.TestUpload
ch <- measurement
}
// Signal we've finished reading counterflow messages.
errors <- nil
errCh <- nil
}

// emit emits an event during the upload.
Expand Down
24 changes: 12 additions & 12 deletions internal/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func TestSetReadDeadlineError(t *testing.T) {
SetReadDeadlineResult: mockedErr,
}
ch := make(chan spec.Measurement, 128)
errs := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errs)
err := <-errs
errCh := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errCh)
err := <-errCh
if err != mockedErr {
t.Fatal("Not the error we expected")
}
Expand All @@ -58,9 +58,9 @@ func TestReadMessageError(t *testing.T) {
ReadMessageResult: mockedErr,
}
ch := make(chan spec.Measurement, 128)
errs := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errs)
err := <-errs
errCh := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errCh)
err := <-errCh
if err != mockedErr {
t.Fatal("Not the error we expected")
}
Expand All @@ -72,9 +72,9 @@ func TestReadNonTextMessageError(t *testing.T) {
MessageByteArray: []byte("abcdef"),
}
ch := make(chan spec.Measurement, 128)
errs := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errs)
err := <-errs
errCh := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errCh)
err := <-errCh
if err != errNonTextMessage {
t.Fatal("Not the error we expected")
}
Expand All @@ -86,9 +86,9 @@ func TestReadNonJSONError(t *testing.T) {
MessageByteArray: []byte("{"),
}
ch := make(chan spec.Measurement, 128)
errs := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errs)
err := <-errs
errCh := make(chan error)
go readcounterflow(context.Background(), &conn, ch, errCh)
err := <-errCh
var syntaxError *json.SyntaxError
if !errors.As(err, &syntaxError) {
t.Fatal("Not the error we expected")
Expand Down

0 comments on commit f5cd4aa

Please sign in to comment.