Skip to content

Commit 044276a

Browse files
authored
Trying to fix CI (#49)
* Trying to fix CI * Fix races * test for races
1 parent e4642ca commit 044276a

5 files changed

Lines changed: 29 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
runs-on: ${{ matrix.os }}-latest
5050
strategy:
5151
matrix:
52-
os: [ubuntu]
52+
os: [ubuntu, windows, macos]
5353
steps:
5454
- uses: actions/checkout@v6
5555

@@ -59,12 +59,14 @@ jobs:
5959
go-version: stable
6060

6161
- name: Test
62-
run: |
63-
go test -v -coverprofile="coverage.tmp.txt" ./...
64-
cat coverage.tmp.txt | grep -v "demo-app" | grep -v "platforma/docs" > coverage.txt
62+
run: go test -v -race -coverprofile="coverage.tmp.txt" ./...
63+
64+
- name: Filter coverage
65+
if: matrix.os == 'ubuntu'
66+
run: cat coverage.tmp.txt | grep -v "demo-app" | grep -v "platforma/docs" > coverage.txt
6567

6668
- name: Upload coverage reports to Codecov
67-
# upload coverage reports only once
69+
if: matrix.os == 'ubuntu'
6870
uses: shogo82148/actions-goveralls@25f5320d970fb565100cf1993ada29be1bb196a1
6971
with:
7072
path-to-profile: coverage.txt

Taskfile.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tasks:
1111

1212
test:
1313
cmds:
14-
- go test -coverprofile=coverage.tmp.out ./...
14+
- go test -race -coverprofile=coverage.tmp.out ./...
1515
- cat coverage.tmp.out | grep -v "demo-app" | grep -v "platforma/docs" > coverage.out
1616
- go tool cover -html=coverage.out -o coverage.html
1717

database/database_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build linux
2+
13
package database_test
24

35
import (

queue/processor_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package queue_test
33
import (
44
"context"
55
"errors"
6+
"sync/atomic"
67
"testing"
78
"time"
89

@@ -15,14 +16,14 @@ func TestProcessor(t *testing.T) {
1516
t.Run("simple queue", func(t *testing.T) {
1617
t.Parallel()
1718
ctx := context.Background()
18-
res := 0
19+
var res atomic.Int32
1920

2021
q := &mockQueue[job]{
2122
jobChan: make(chan job, 10),
2223
}
2324

2425
p := queue.New(queue.HandlerFunc[job](func(_ context.Context, job job) {
25-
res += job.data
26+
res.Add(int32(job.data))
2627
}), q, 4, time.Microsecond)
2728

2829
go p.Run(context.TODO())
@@ -31,10 +32,10 @@ func TestProcessor(t *testing.T) {
3132
p.Enqueue(ctx, job{data: 1})
3233
p.Enqueue(ctx, job{data: 1})
3334

34-
time.Sleep(1 * time.Millisecond)
35+
time.Sleep(100 * time.Millisecond)
3536

36-
if res != 3 {
37-
t.Errorf("expected res to be 1, got %d", res)
37+
if res.Load() != 3 {
38+
t.Errorf("expected res to be 3, got %d", res.Load())
3839
}
3940
})
4041

scheduler/scheduler_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package scheduler_test
22

33
import (
4-
"bytes"
54
"context"
65
"errors"
6+
"sync/atomic"
77
"testing"
88
"time"
99

@@ -14,45 +14,45 @@ import (
1414
func TestSuccessRun(t *testing.T) {
1515
t.Parallel()
1616

17-
buf := bytes.Buffer{}
17+
var counter atomic.Int32
1818
s := scheduler.New(1*time.Second, application.RunnerFunc(func(ctx context.Context) error {
19-
buf.WriteString("1")
19+
counter.Add(1)
2020
return nil
2121
}))
2222

2323
go s.Run(context.TODO())
2424

2525
time.Sleep(3500 * time.Millisecond)
2626

27-
if buf.String() != "111" {
28-
t.Errorf("wrong buffer content. expected %v, got %v", "111", buf.String())
27+
if counter.Load() != 3 {
28+
t.Errorf("wrong counter value. expected %v, got %v", 3, counter.Load())
2929
}
3030
}
3131

3232
func TestErrorRun(t *testing.T) {
3333
t.Parallel()
3434

35-
buf := bytes.Buffer{}
35+
var counter atomic.Int32
3636
s := scheduler.New(1*time.Second, application.RunnerFunc(func(ctx context.Context) error {
37-
buf.WriteString("1")
37+
counter.Add(1)
3838
return errors.New("some error")
3939
}))
4040

4141
go s.Run(context.TODO())
4242

4343
time.Sleep(3500 * time.Millisecond)
4444

45-
if buf.String() != "111" {
46-
t.Errorf("wrong buffer content. expected %v, got %v", "111", buf.String())
45+
if counter.Load() != 3 {
46+
t.Errorf("wrong counter value. expected %v, got %v", 3, counter.Load())
4747
}
4848
}
4949

5050
func TestContextDecline(t *testing.T) {
5151
t.Parallel()
5252

53-
buf := bytes.Buffer{}
53+
var counter atomic.Int32
5454
s := scheduler.New(1*time.Second, application.RunnerFunc(func(ctx context.Context) error {
55-
buf.WriteString("1")
55+
counter.Add(1)
5656
return nil
5757
}))
5858

@@ -65,8 +65,8 @@ func TestContextDecline(t *testing.T) {
6565

6666
err := s.Run(ctx)
6767

68-
if buf.String() != "111" {
69-
t.Errorf("wrong buffer content. expected %v, got %v", "111", buf.String())
68+
if counter.Load() != 3 {
69+
t.Errorf("wrong counter value. expected %v, got %v", 3, counter.Load())
7070
}
7171

7272
if err == nil {

0 commit comments

Comments
 (0)