Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
fix staticcheck failures
Browse files Browse the repository at this point in the history
Signed-off-by: SataQiu <[email protected]>
  • Loading branch information
SataQiu committed Aug 28, 2019
1 parent f108b62 commit 37ca9e4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (client *APIClient) hijack(ctx context.Context, path string, query url.Valu
tcpConn.SetKeepAlivePeriod(30 * time.Second)
}

//lint:ignore SA1019 we do not migrate this to 'net/http.Client' as it does not implement Hijack now.
clientconn := httputil.NewClientConn(conn, nil)
defer clientconn.Close()

Expand Down Expand Up @@ -142,6 +143,8 @@ func (client *APIClient) sendRequest(ctx context.Context, method, path string, q
return nil, err
}

req = req.WithContext(ctx)

resp, err := cancellableDo(ctx, client.HTTPCli, req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -181,8 +184,6 @@ func cancellableDo(ctx context.Context, client *http.Client, req *http.Request)

select {
case <-ctx.Done():
tr := client.Transport.(*http.Transport)
tr.CancelRequest(req)
<-ctxResp
return nil, ctx.Err()

Expand Down
3 changes: 3 additions & 0 deletions dfget/core/api/supernode_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ func (s *SupernodeAPITestSuite) TestSupernodeAPI_Register(c *check.C) {
res := types.RegisterResponse{BaseResponse: &types.BaseResponse{}}
s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(200, []byte(res.String()), nil)
r, e = s.api.Register(localhost, createRegisterRequest())
c.Assert(e, check.IsNil)
c.Assert(r, check.NotNil)
c.Assert(r.Code, check.Equals, 0)

res.Code = constants.Success
res.Data = &types.RegisterResponseData{FileLength: int64(32)}
s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(200, []byte(res.String()), nil)
r, e = s.api.Register(localhost, createRegisterRequest())
c.Assert(e, check.IsNil)
c.Assert(r, check.NotNil)
c.Assert(r.Code, check.Equals, constants.Success)
c.Assert(r.Data.FileLength, check.Equals, res.Data.FileLength)
Expand Down Expand Up @@ -140,6 +142,7 @@ func (s *SupernodeAPITestSuite) TestSupernodeAPI_get(c *check.C) {
c.Assert(e.Error(), check.Equals, "0:test", check.Commentf(m))

r, e, m = f(0, "x", fmt.Errorf("test error"))
c.Assert(r.A, check.Equals, 0, check.Commentf(m))
c.Assert(e.Error(), check.Equals, "test error", check.Commentf(m))

r, e, m = f(200, "x", nil)
Expand Down
2 changes: 1 addition & 1 deletion dfget/core/uploader/peer_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func (s *PeerServerTestSuite) TearDownSuite(c *check.C) {
func (s *PeerServerTestSuite) TestGetTaskFile(c *check.C) {
// normal test
f, _, err := s.srv.getTaskFile(commonFile)
defer f.Close()
// check get file correctly
c.Assert(err, check.IsNil)
c.Assert(f, check.NotNil)
defer f.Close()
// check read file correctly
result, err := ioutil.ReadAll(f)
c.Assert(err, check.IsNil)
Expand Down
4 changes: 2 additions & 2 deletions dfget/core/uploader/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func serverGC(cfg *config.Config, interval time.Duration) {
}

func captureQuitSignal() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGSTOP)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
s := <-c
logrus.Infof("capture stop signal: %s, will shutdown...", s)

Expand Down
1 change: 1 addition & 0 deletions supernode/daemon/mgr/dfgettask/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (s *DfgetTaskMgrTestSuite) TestDfgetTaskUpdate(c *check.C) {
}

dt, err := manager.Get(context.Background(), tc.dfgetTask.CID, tc.dfgetTask.TaskID)
c.Check(err, check.IsNil)
c.Check(dt, check.DeepEquals, tc.Expect)
}
}
Expand Down

0 comments on commit 37ca9e4

Please sign in to comment.