Skip to content

Commit

Permalink
fix: tests, lint and deepsource
Browse files Browse the repository at this point in the history
  • Loading branch information
aloknerurkar committed Jul 21, 2021
1 parent 72ac978 commit 166086d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
9 changes: 0 additions & 9 deletions pkg/api/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ func (s *server) processUploadRequest(

// add the tag to the context if it exists
ctx = sctx.SetTag(r.Context(), tag)

// increment the StateSplit here since we dont have a splitter for the file upload
err = tag.Inc(tags.StateSplit)
if err != nil {
s.logger.Debugf("chunk upload: increment tag: %v", err)
s.logger.Error("chunk upload: increment tag")
return nil, nil, nil, errors.New("cannot increment tag")
}
} else {
ctx = r.Context()
}
Expand Down Expand Up @@ -80,7 +72,6 @@ func (s *server) processUploadRequest(
}

func (s *server) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("handling")
ctx, tag, putter, err := s.processUploadRequest(r)
if err != nil {
jsonhttp.BadRequest(w, err.Error())
Expand Down
17 changes: 8 additions & 9 deletions pkg/api/chunk_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *server) handleUploadStream(

var (
gone = make(chan struct{})
ticker = time.NewTicker(time.Second * 4)
ticker = time.NewTicker(uploadPingTimout)
err error
)
defer func() {
Expand All @@ -82,8 +82,7 @@ func (s *server) handleUploadStream(
// default handlers for ping/pong
conn.SetPingHandler(nil)
conn.SetPongHandler(func(string) error {
conn.SetReadDeadline(time.Now().Add(readDeadline))
return nil
return conn.SetReadDeadline(time.Now().Add(readDeadline))
})

sendMsg := func(msgType int, buf []byte) error {
Expand All @@ -98,22 +97,22 @@ func (s *server) handleUploadStream(
return nil
}

sendErrorClose := func(code int, errmsg string) error {
return conn.WriteControl(
sendErrorClose := func(code int, errmsg string) {
err := conn.WriteControl(
websocket.CloseMessage,
websocket.FormatCloseMessage(code, errmsg),
time.Now().Add(writeDeadline),
)
if err != nil {
s.logger.Errorf("failed sending close msg with err, reason: %s", err.Error())
}
}

for {
select {
case <-s.quit:
// shutdown
err := sendErrorClose(websocket.CloseGoingAway, "node shutting down")
if err != nil {
s.logger.Debugf("failed sending close message: %v", err)
}
sendErrorClose(websocket.CloseGoingAway, "node shutting down")
return
case <-gone:
// client gone
Expand Down
6 changes: 2 additions & 4 deletions pkg/api/chunk_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ func TestChunkUploadStream(t *testing.T) {
}
if cerr, ok := err.(*websocket.CloseError); !ok {
t.Fatal("invalid error on read")
} else {
if cerr.Text != "invalid message" {
t.Fatalf("incorrect response on error, exp: (invalid message) got (%s)", cerr.Text)
}
} else if cerr.Text != "invalid message" {
t.Fatalf("incorrect response on error, exp: (invalid message) got (%s)", cerr.Text)
}
})
}

0 comments on commit 166086d

Please sign in to comment.