Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update vulnerable dependencies and use std error.Join #9

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.19.x, 1.20.x, 1.21.x, 1.22.x]
go-version: [1.21.x, 1.22.x]
steps:
- name: Install Go
uses: actions/setup-go@v4
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ test-xml: test-cov gocov-xml
# ========= Helpers ===========

golangci-lint:
$(call install-if-needed,GOLANGCI_LINT,github.com/golangci/golangci-lint/cmd/golangci-lint,v1.53.3)
$(call install-if-needed,GOLANGCI_LINT,github.com/golangci/golangci-lint/cmd/golangci-lint,v1.59.1)

gci:
$(call install-if-needed,GCI_BIN,github.com/daixiang0/gci,v0.10.1)
$(call install-if-needed,GCI_BIN,github.com/daixiang0/gci,v0.13.4)

gocov:
$(call install-if-needed,GOCOV,github.com/axw/gocov/gocov,v1.0.0)
$(call install-if-needed,GOCOV,github.com/axw/gocov/gocov,v1.1.0)

gocov-xml:
$(call install-if-needed,GOCOVXML,github.com/AlekSi/gocov-xml,v1.0.0)
$(call install-if-needed,GOCOVXML,github.com/AlekSi/gocov-xml,v1.1.0)

is-available = $(if $(wildcard $(LOCAL_GO_BIN_DIR)/$(1)),$(LOCAL_GO_BIN_DIR)/$(1),$(if $(shell command -v $(1) 2> /dev/null),yes,no))

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ $ go get github.com/gojekfarm/xrun

## Usage

> Minimum Required Go Version: 1.20.x

- [API reference][api-docs]
- [Blog post explaining motivation behind xrun][blog-link]
- [Reddit post][reddit-link]
Expand Down
2 changes: 2 additions & 0 deletions component/http_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func (s *HTTPServerSuite) TestHTTPServer() {
} else {
s.NoError(<-errCh)
}

time.Sleep(50 * time.Millisecond) // for goroutine to exit
})
}
}
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ module github.com/gojekfarm/xrun

go 1.19

require (
github.com/hashicorp/go-multierror v1.1.1
github.com/stretchr/testify v1.7.0
)
require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
17 changes: 6 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
14 changes: 6 additions & 8 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"sync"
"time"

"github.com/hashicorp/go-multierror"
)

// NewManager creates a Manager and applies provided Option
Expand Down Expand Up @@ -116,9 +114,9 @@ func (m *Manager) engageStopProcedure() error {
defer m.mu.Unlock()
m.stopping = true

var retErr *multierror.Error
var retErr error

retErrCh := make(chan *multierror.Error, 1)
retErrCh := make(chan error, 1)

go m.aggregateErrors(retErrCh)
go func() {
Expand All @@ -136,7 +134,7 @@ func (m *Manager) engageStopProcedure() error {
return fmt.Errorf("not all components were shutdown completely within grace period(%s): %w", m.shutdownTimeout, err)
}

return retErr.ErrorOrNil()
return retErr
}

func (m *Manager) cancelFunc() context.CancelFunc {
Expand All @@ -150,10 +148,10 @@ func (m *Manager) cancelFunc() context.CancelFunc {
return shutdownCancel
}

func (m *Manager) aggregateErrors(ch chan<- *multierror.Error) {
var r *multierror.Error
func (m *Manager) aggregateErrors(ch chan<- error) {
var r error
for err := range m.errChan {
r = multierror.Append(r, err)
r = errors.Join(r, err)
}
ch <- r
}
59 changes: 26 additions & 33 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *ManagerSuite) TestNewManager() {
wantErr: assert.NoError,
components: []Component{
ComponentFunc(func(ctx context.Context) error {
time.Sleep(3 * time.Second)
time.Sleep(300 * time.Millisecond)
<-ctx.Done()
return nil
}),
Expand All @@ -52,13 +52,13 @@ func (s *ManagerSuite) TestNewManager() {
},
{
name: "WithGracefulShutdownErrorOnOneComponent",
options: []Option{ShutdownTimeout(5 * time.Second)},
options: []Option{ShutdownTimeout(time.Second)},
wantErr: assert.Error,
components: []Component{
ComponentFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
<-ctx.Done()
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
return nil
}),
ComponentFunc(func(ctx context.Context) error {
Expand All @@ -74,15 +74,15 @@ func (s *ManagerSuite) TestNewManager() {
wantErr: assert.NoError,
components: []Component{
ComponentFunc(func(ctx context.Context) error {
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
<-ctx.Done()
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
return nil
}),
ComponentFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
<-ctx.Done()
time.Sleep(10 * time.Second)
time.Sleep(time.Second)
return nil
}),
},
Expand All @@ -92,9 +92,8 @@ func (s *ManagerSuite) TestNewManager() {
wantErr: assert.NoError,
components: []Component{
ComponentFunc(func(ctx context.Context) error {
time.Sleep(5 * time.Second)
<-ctx.Done()
time.Sleep(5 * time.Second)
time.Sleep(2 * time.Second)
return nil
}),
},
Expand All @@ -104,65 +103,59 @@ func (s *ManagerSuite) TestNewManager() {
wantErr: assert.NoError,
components: []Component{
ComponentFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
<-ctx.Done()
time.Sleep(2 * time.Second)
time.Sleep(200 * time.Millisecond)
return nil
}),
ComponentFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
<-ctx.Done()
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
return ctx.Err()
}),
},
},
{
name: "ShutdownWhenOneComponentReturnsErrorOnExit",
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
return assert.EqualError(t, err, `1 error occurred:
* shutdown error

`, i...)
return assert.EqualError(t, err, "shutdown error", i...)
},
components: []Component{
ComponentFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
<-ctx.Done()
time.Sleep(2 * time.Second)
time.Sleep(200 * time.Millisecond)
return nil
}),
ComponentFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
<-ctx.Done()
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
return errors.New("shutdown error")
}),
},
},
{
name: "ShutdownWhenMoreThanOneComponentReturnsErrorOnExit",
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
return assert.EqualError(t, err, `2 errors occurred:
* shutdown error 2
* shutdown error 1

`, i...)
return assert.EqualError(t, err, `shutdown error 2
shutdown error 1`, i...)
},
components: []Component{
ComponentFunc(func(ctx context.Context) error {
<-ctx.Done()
time.Sleep(2 * time.Second)
time.Sleep(200 * time.Millisecond)
return nil
}),
ComponentFunc(func(ctx context.Context) error {
<-ctx.Done()
time.Sleep(3 * time.Second)
time.Sleep(300 * time.Millisecond)
return errors.New("shutdown error 1")
}),
ComponentFunc(func(ctx context.Context) error {
<-ctx.Done()
time.Sleep(2 * time.Second)
time.Sleep(200 * time.Millisecond)
return errors.New("shutdown error 2")
}),
},
Expand All @@ -184,7 +177,7 @@ func (s *ManagerSuite) TestNewManager() {
errCh <- m.Run(ctx)
}()

time.Sleep(1 * time.Second)
time.Sleep(300 * time.Millisecond)
cancel()

t.wantErr(s.T(), <-errCh)
Expand All @@ -202,7 +195,7 @@ func (s *ManagerSuite) TestAddNewComponentAfterStop() {
errCh <- m.Run(ctx)
}()

time.Sleep(1 * time.Second)
time.Sleep(100 * time.Millisecond)
cancel()

s.NoError(<-errCh)
Expand All @@ -222,7 +215,7 @@ func (s *ManagerSuite) TestAddNewComponentAfterStart() {
errCh <- m.Run(ctx)
}()

time.Sleep(1 * time.Second)
time.Sleep(100 * time.Millisecond)

s.EqualError(m.Add(ComponentFunc(func(ctx context.Context) error {
return nil
Expand Down
Loading