Skip to content

Commit ece533e

Browse files
authored
[#180]: feature: remove semaphores, add go 1.23 support
2 parents 3abcbc4 + e21a413 commit ece533e

File tree

10 files changed

+51
-37
lines changed

10 files changed

+51
-37
lines changed

.github/workflows/linters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
- "**.md"
1616

1717
jobs:
18-
golangci-lint:
18+
linters:
1919
name: Golang-CI (lint)
2020
runs-on: ubuntu-latest
2121
steps:

dep/in_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package dep
33
import (
44
"reflect"
55
"testing"
6-
7-
"github.com/stretchr/testify/assert"
86
)
97

108
type BarBaz interface {
@@ -17,5 +15,7 @@ func TestImplements(t *testing.T) {
1715
println("foo")
1816
}, (*BarBaz)(nil))
1917

20-
assert.Equal(t, reflect.Interface, in.Type.Kind())
18+
if reflect.Interface != in.Type.Kind() {
19+
t.Fail()
20+
}
2121
}

dep/out_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package dep
33
import (
44
"reflect"
55
"testing"
6-
7-
"github.com/stretchr/testify/assert"
86
)
97

108
type FooBar interface {
@@ -27,6 +25,11 @@ func TestOutType(t *testing.T) {
2725
p := Plugin{}
2826
tt := Bind((*FooBar)(nil), p.F)
2927

30-
assert.Equal(t, reflect.Interface, tt.Type.Kind())
31-
assert.Equal(t, "F", tt.Method)
28+
if reflect.Interface != tt.Type.Kind() {
29+
t.Fail()
30+
}
31+
32+
if tt.Method != "F" {
33+
t.Fail()
34+
}
3235
}

go.mod

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,4 @@ go 1.23
44

55
toolchain go1.23.0
66

7-
require (
8-
github.com/roadrunner-server/errors v1.4.1
9-
github.com/stretchr/testify v1.9.0
10-
golang.org/x/sync v0.8.0
11-
)
12-
13-
require (
14-
github.com/davecgh/go-spew v1.1.1 // indirect
15-
github.com/pmezard/go-difflib v1.0.0 // indirect
16-
gopkg.in/yaml.v3 v3.0.1 // indirect
17-
)
7+
require github.com/roadrunner-server/errors v1.4.1

go.sum

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,2 @@
1-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
51
github.com/roadrunner-server/errors v1.4.1 h1:LKNeaCGiwd3t8IaL840ZNF3UA9yDQlpvHnKddnh0YRQ=
62
github.com/roadrunner-server/errors v1.4.1/go.mod h1:qeffnIKG0e4j1dzGpa+OGY5VKSfMphizvqWIw8s2lAo=
7-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
8-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
9-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
10-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
11-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
12-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
13-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
14-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ go 1.23.0
22

33
use (
44
.
5+
./tests
56
./examples/sample_1
67
)

go.work.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
1919
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
2020
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
2121
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
22+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
2223
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2324
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
2425
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=

stop.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"reflect"
88
"sync"
99

10-
"golang.org/x/sync/semaphore"
11-
1210
"github.com/roadrunner-server/errors"
1311
)
1412

@@ -24,20 +22,23 @@ func (e *Endure) stop() error {
2422

2523
mu := new(sync.Mutex)
2624
errs := make([]error, 0, 2)
27-
sema := semaphore.NewWeighted(int64(len(vertices)))
25+
wg := &sync.WaitGroup{}
26+
wg.Add(len(vertices))
2827

2928
// reverse order
3029
for i := len(vertices) - 1; i >= 0; i-- {
3130
if !vertices[i].IsActive() {
31+
wg.Done()
3232
continue
3333
}
3434

3535
if !reflect.TypeOf(vertices[i].Plugin()).Implements(reflect.TypeOf((*Service)(nil)).Elem()) {
36+
wg.Done()
3637
continue
3738
}
3839

39-
_ = sema.Acquire(context.Background(), 1)
4040
go func(i int) {
41+
defer wg.Done()
4142
stopMethod, _ := reflect.TypeOf(vertices[i].Plugin()).MethodByName(StopMethodName)
4243

4344
var inVals []reflect.Value
@@ -59,12 +60,11 @@ func (e *Endure) stop() error {
5960
mu.Unlock()
6061
}
6162

62-
sema.Release(1)
6363
cancel()
6464
}(i)
6565
}
6666

67-
_ = sema.Acquire(context.Background(), int64(len(vertices)))
67+
wg.Wait()
6868

6969
if len(errs) > 0 {
7070
return stderr.Join(errs...)

tests/go.mod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module github.com/roadrunner-server/endure/v2/tests
2+
3+
go 1.23
4+
5+
toolchain go1.23.0
6+
7+
replace github.com/roadrunner-server/endure/v2 => ../
8+
9+
require (
10+
github.com/roadrunner-server/endure/v2 v2.0.0-00010101000000-000000000000
11+
github.com/roadrunner-server/errors v1.4.1
12+
github.com/stretchr/testify v1.9.0
13+
)
14+
15+
require (
16+
github.com/davecgh/go-spew v1.1.1 // indirect
17+
github.com/pmezard/go-difflib v1.0.0 // indirect
18+
gopkg.in/yaml.v3 v3.0.1 // indirect
19+
)

tests/go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/roadrunner-server/errors v1.4.1 h1:LKNeaCGiwd3t8IaL840ZNF3UA9yDQlpvHnKddnh0YRQ=
6+
github.com/roadrunner-server/errors v1.4.1/go.mod h1:qeffnIKG0e4j1dzGpa+OGY5VKSfMphizvqWIw8s2lAo=
7+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
8+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
11+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)