Skip to content

Commit ead72ef

Browse files
committed
chore(ci): separate tests
Signed-off-by: Valery Piashchynski <[email protected]>
1 parent 82ae444 commit ead72ef

File tree

11 files changed

+120
-110
lines changed

11 files changed

+120
-110
lines changed

.github/workflows/linux.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Linux
1+
name: tests
22

33
on: [push, pull_request]
44

@@ -32,10 +32,36 @@ jobs:
3232
run: go mod download
3333

3434
- name: Run golang tests with coverage
35-
run: make test_coverage
35+
run: |
36+
cd tests
37+
mkdir ./coverage
38+
go test -v -race -cover -coverpkg=./... -coverprofile=./coverage/pq-${{ matrix.os }}.out -covermode=atomic ./...
3639
37-
- uses: codecov/codecov-action@v4 # Docs: <https://github.com/codecov/codecov-action>
40+
- name: Archive code coverage results
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: pq-${{ matrix.os }}
44+
path: ./tests/coverage/pq-${{ matrix.os }}.out
45+
46+
codecov:
47+
name: Upload codecov
48+
runs-on: ubuntu-latest
49+
needs:
50+
- golang
51+
52+
timeout-minutes: 60
53+
steps:
54+
- name: Download code coverage results
55+
uses: actions/download-artifact@v4
56+
- run: |
57+
cd pq-ubuntu-latest
58+
echo 'mode: atomic' > summary.txt
59+
tail -q -n +2 *.out >> summary.txt
60+
sed -i '2,${/roadrunner/!d}' summary.txt
61+
62+
- name: upload to codecov
63+
uses: codecov/codecov-action@v4 # Docs: <https://github.com/codecov/codecov-action>
3864
with:
3965
token: ${{ secrets.CODECOV_TOKEN }}
40-
file: ./coverage-ci/summary.txt
66+
file: ./coverage/summary.txt
4167
fail_ci_if_error: false

binary_heap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewBinHeap[T Item](maxLen uint64) *BinHeap[T] {
3434
return &BinHeap[T]{
3535
items: make([]T, 0, 1000),
3636
exists: make(map[string]struct{}, 1000),
37-
st: newStack(),
37+
st: NewStack(),
3838
len: 0,
3939
maxLen: maxLen,
4040
cond: sync.Cond{L: &sync.Mutex{}},
@@ -107,11 +107,11 @@ func (bh *BinHeap[T]) Remove(groupID string) []T {
107107
// delete element
108108
delete(bh.exists, bh.items[i].ID())
109109
out = append(out, bh.items[i])
110-
bh.st.add(i)
110+
bh.st.Add(i)
111111
}
112112
}
113113

114-
ids := bh.st.indices()
114+
ids := bh.st.Indices()
115115
adjusment := 0
116116
for i := 0; i < len(ids); i++ {
117117
start := ids[i][0] - adjusment

go.mod

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
module github.com/roadrunner-server/priority_queue
22

33
go 1.22.4
4-
5-
require (
6-
github.com/google/uuid v1.6.0
7-
github.com/stretchr/testify v1.9.0
8-
)
9-
10-
require (
11-
github.com/davecgh/go-spew v1.1.1 // indirect
12-
github.com/pmezard/go-difflib v1.0.0 // indirect
13-
gopkg.in/yaml.v3 v3.0.1 // indirect
14-
)

go.sum

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
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/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4-
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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=

monotonic_stack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ type stack struct {
88
idx [][2]int
99
}
1010

11-
func newStack() *stack {
11+
func NewStack() *stack {
1212
return &stack{
1313
idx: make([][2]int, 0, 10),
1414
}
1515
}
1616

17-
func (st *stack) add(idx int) {
17+
func (st *stack) Add(idx int) {
1818
/*
1919
we have to store the beginning of the range + the last
2020
*/
@@ -40,7 +40,7 @@ func (st *stack) add(idx int) {
4040
})
4141
}
4242

43-
func (st *stack) indices() [][2]int {
43+
func (st *stack) Indices() [][2]int {
4444
return st.idx
4545
}
4646

monotonic_stack_test.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

pull_request_template.md

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package priorityqueue
1+
package priorityqueue_test
22

33
import (
44
"fmt"
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/google/uuid"
12+
priorityqueue "github.com/roadrunner-server/priority_queue"
1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415
)
@@ -40,7 +41,7 @@ func (t Test) Priority() int64 {
4041
}
4142

4243
func TestBinHeap_Init(t *testing.T) {
43-
a := []Item{
44+
a := []priorityqueue.Item{
4445
NewTest(2, uuid.NewString(), uuid.NewString()),
4546
NewTest(23, uuid.NewString(), uuid.NewString()),
4647
NewTest(33, uuid.NewString(), uuid.NewString()),
@@ -54,7 +55,7 @@ func TestBinHeap_Init(t *testing.T) {
5455
NewTest(99, uuid.NewString(), uuid.NewString()),
5556
}
5657

57-
bh := NewBinHeap[Item](12)
58+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](12)
5859

5960
for i := 0; i < len(a); i++ {
6061
bh.Insert(a[i])
@@ -86,7 +87,7 @@ func TestBinHeap_Init(t *testing.T) {
8687
}
8788

8889
func TestBinHeap_MaxLen(t *testing.T) {
89-
a := []Item{
90+
a := []priorityqueue.Item{
9091
NewTest(2, uuid.NewString(), uuid.NewString()),
9192
NewTest(23, uuid.NewString(), uuid.NewString()),
9293
NewTest(33, uuid.NewString(), uuid.NewString()),
@@ -100,10 +101,10 @@ func TestBinHeap_MaxLen(t *testing.T) {
100101
NewTest(99, uuid.NewString(), uuid.NewString()),
101102
}
102103

103-
bh := NewBinHeap[Item](1)
104+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](1)
104105

105106
go func() {
106-
res := make([]Item, 0, 12)
107+
res := make([]priorityqueue.Item, 0, 12)
107108

108109
for i := 0; i < 11; i++ {
109110
item := bh.ExtractMin()
@@ -124,7 +125,7 @@ func TestNewPriorityQueue(t *testing.T) {
124125
insertsPerSec := uint64(0)
125126
getPerSec := uint64(0)
126127
stopCh := make(chan struct{}, 1)
127-
pq := NewBinHeap[Item](1000)
128+
pq := priorityqueue.NewBinHeap[priorityqueue.Item](1000)
128129

129130
go func() {
130131
tt3 := time.NewTicker(time.Millisecond * 10)
@@ -187,7 +188,7 @@ func TestNewPriorityQueue(t *testing.T) {
187188
}
188189

189190
func TestNewItemWithTimeout(t *testing.T) {
190-
a := []Item{
191+
a := []priorityqueue.Item{
191192
NewTest(5, uuid.NewString(), uuid.NewString()),
192193
NewTest(23, uuid.NewString(), uuid.NewString()),
193194
NewTest(33, uuid.NewString(), uuid.NewString()),
@@ -205,7 +206,7 @@ func TestNewItemWithTimeout(t *testing.T) {
205206
first item should be extracted not less than 5 seconds after we call ExtractMin
206207
5 seconds is a minimum timeout for our items
207208
*/
208-
bh := NewBinHeap[Item](100)
209+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](100)
209210

210211
for i := 0; i < len(a); i++ {
211212
bh.Insert(a[i])
@@ -218,7 +219,7 @@ func TestNewItemWithTimeout(t *testing.T) {
218219
}
219220

220221
func TestItemPeek(t *testing.T) {
221-
a := []Item{
222+
a := []priorityqueue.Item{
222223
NewTest(5, uuid.NewString(), uuid.NewString()),
223224
NewTest(23, uuid.NewString(), uuid.NewString()),
224225
NewTest(33, uuid.NewString(), uuid.NewString()),
@@ -236,7 +237,7 @@ func TestItemPeek(t *testing.T) {
236237
first item should be extracted not less than 5 seconds after we call ExtractMin
237238
5 seconds is a minimum timeout for our items
238239
*/
239-
bh := NewBinHeap[Item](100)
240+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](100)
240241

241242
for i := 0; i < len(a); i++ {
242243
bh.Insert(a[i])
@@ -252,7 +253,7 @@ func TestItemPeek(t *testing.T) {
252253
}
253254

254255
func TestItemPeekConcurrent(t *testing.T) {
255-
a := []Item{
256+
a := []priorityqueue.Item{
256257
NewTest(5, uuid.NewString(), uuid.NewString()),
257258
NewTest(23, uuid.NewString(), uuid.NewString()),
258259
NewTest(33, uuid.NewString(), uuid.NewString()),
@@ -270,7 +271,7 @@ func TestItemPeekConcurrent(t *testing.T) {
270271
first item should be extracted not less than 5 seconds after we call ExtractMin
271272
5 seconds is a minimum timeout for our items
272273
*/
273-
bh := NewBinHeap[Item](100)
274+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](100)
274275

275276
for i := 0; i < len(a); i++ {
276277
bh.Insert(a[i])
@@ -298,7 +299,7 @@ func TestItemPeekConcurrent(t *testing.T) {
298299
}
299300

300301
func TestBinHeap_Remove(t *testing.T) {
301-
a := []Item{
302+
a := []priorityqueue.Item{
302303
NewTest(2, "1", "101"),
303304
NewTest(5, "1", "102"),
304305
NewTest(99, "1", "103"),
@@ -312,13 +313,13 @@ func TestBinHeap_Remove(t *testing.T) {
312313
NewTest(2, "1", "111"),
313314
}
314315

315-
bh := NewBinHeap[Item](12)
316+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](12)
316317

317318
for i := 0; i < len(a); i++ {
318319
bh.Insert(a[i])
319320
}
320321

321-
expected := []Item{
322+
expected := []priorityqueue.Item{
322323
NewTest(4, "6", "104"),
323324
NewTest(6, "7", "105"),
324325
NewTest(23, "2", "106"),
@@ -337,7 +338,7 @@ func TestBinHeap_Remove(t *testing.T) {
337338
}
338339
}
339340

340-
res := make([]Item, 0, 12)
341+
res := make([]priorityqueue.Item, 0, 12)
341342

342343
for i := 0; i < 5; i++ {
343344
item := bh.ExtractMin()
@@ -349,7 +350,7 @@ func TestBinHeap_Remove(t *testing.T) {
349350

350351
func TestExists(t *testing.T) {
351352
const id = "11111111111"
352-
a := []Item{
353+
a := []priorityqueue.Item{
353354
NewTest(2, "1", id),
354355
NewTest(5, "1", uuid.NewString()),
355356
NewTest(99, "1", uuid.NewString()),
@@ -363,7 +364,7 @@ func TestExists(t *testing.T) {
363364
NewTest(2, "1", uuid.NewString()),
364365
}
365366

366-
bh := NewBinHeap[Item](12)
367+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](12)
367368

368369
for i := 0; i < len(a); i++ {
369370
bh.Insert(a[i])
@@ -378,7 +379,7 @@ func TestExists(t *testing.T) {
378379
}
379380

380381
func BenchmarkGeneral(b *testing.B) {
381-
bh := NewBinHeap[Item](100)
382+
bh := priorityqueue.NewBinHeap[priorityqueue.Item](100)
382383
id := uuid.NewString()
383384
id2 := uuid.NewString()
384385

tests/go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module github.com/roadrunner-server/priority_queue/tests
2+
3+
go 1.22.4
4+
5+
require (
6+
github.com/google/uuid v1.6.0
7+
github.com/roadrunner-server/priority_queue v1.0.0
8+
github.com/stretchr/testify v1.9.0
9+
)
10+
11+
replace github.com/roadrunner-server/priority_queue => ../
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+
)

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/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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)