Skip to content

Commit

Permalink
Add Codecov and race detector (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
destel authored Mar 26, 2024
1 parent 5017876 commit 6b55a1c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ jobs:
${{ runner.os }}-go-
- name: Run tests
run: go test -v ./...
run: go test -race ./...

- name: Run coverage
run: go test -coverprofile=coverage.out -covermode=atomic ./...

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: destel/rill
13 changes: 8 additions & 5 deletions internal/core/delay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestDelay(t *testing.T) {
}

t.Run("correctness", func(t *testing.T) {
const delay = 2 * time.Second
const eps = 100 * time.Millisecond
const delay = 5 * time.Second
const eps = 1000 * time.Millisecond // Race detector slows down the execution. Need to use larger epsilon

in := make(chan Item)
out := Delay(in, delay)
Expand All @@ -49,13 +49,16 @@ func TestDelay(t *testing.T) {
i++
th.ExpectValue(t, item.Value, i)
th.ExpectValueInDelta(t, time.Since(item.SentAt), delay, eps)
if t.Failed() {
t.FailNow()
}
}
th.ExpectValue(t, i, 100000-1)
})

t.Run("slow producer", func(t *testing.T) {
const delay = 2 * time.Second
const eps = 200 * time.Millisecond
const delay = 5 * time.Second
const eps = 1000 * time.Millisecond

in := make(chan Item)
out := Delay(in, delay)
Expand Down Expand Up @@ -84,7 +87,7 @@ func TestDelay(t *testing.T) {
})

t.Run("slow consumer", func(t *testing.T) {
const delay = 2 * time.Second
const delay = 5 * time.Second

in := make(chan Item)
out := Delay(in, delay)
Expand Down
2 changes: 1 addition & 1 deletion internal/core/loops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func TestBreakable(t *testing.T) {
for x := range in1 {
if x == 100 {
earlyExit()
time.Sleep(1 * time.Second) // give Break some time to react and drain
}

if x > maxSeen {
Expand All @@ -120,6 +119,7 @@ func TestBreakable(t *testing.T) {

}

time.Sleep(1 * time.Second)
th.ExpectDrainedChan(t, in)
})

Expand Down

0 comments on commit 6b55a1c

Please sign in to comment.