mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
Merge pull request #704 from zenixls2/feature/code-coverage
ci: codecoverage
This commit is contained in:
commit
e60e2177f9
9
.github/workflows/go.yml
vendored
9
.github/workflows/go.yml
vendored
|
@ -63,10 +63,15 @@ jobs:
|
||||||
run: go build -v ./cmd/bbgo
|
run: go build -v ./cmd/bbgo
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./pkg/...
|
run: go test -race -coverprofile coverage.txt -covermode atomic ./pkg/...
|
||||||
|
|
||||||
- name: TestDnum
|
- name: TestDnum
|
||||||
run: go test -tags dnum ./pkg/...
|
run: go test -race -coverprofile coverage_dnum.txt -covermode atomic -tags dnum ./pkg/...
|
||||||
|
|
||||||
|
- name: Upload Coverage Report
|
||||||
|
uses: codecov/codecov-action@v3
|
||||||
|
with:
|
||||||
|
files: ./coverage.txt,./coverage_dnum.txt
|
||||||
|
|
||||||
- name: Create dotenv file
|
- name: Create dotenv file
|
||||||
run: |
|
run: |
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -44,3 +44,6 @@ otp*png
|
||||||
|
|
||||||
*.swp
|
*.swp
|
||||||
/pkg/backtest/assets.go
|
/pkg/backtest/assets.go
|
||||||
|
|
||||||
|
coverage.txt
|
||||||
|
coverage_dum.txt
|
||||||
|
|
23
codecov.yml
Normal file
23
codecov.yml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
codecov:
|
||||||
|
require_ci_to_pass: true
|
||||||
|
|
||||||
|
comment:
|
||||||
|
behavior: default
|
||||||
|
layout: "reach,diff,flags,files,footer"
|
||||||
|
require_changes: no
|
||||||
|
|
||||||
|
parsers:
|
||||||
|
gcov:
|
||||||
|
branch_detection:
|
||||||
|
conditional: yes
|
||||||
|
loop: yes
|
||||||
|
method: no
|
||||||
|
macro: no
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
precision: 2
|
||||||
|
round: down
|
||||||
|
range: "70...100"
|
||||||
|
|
||||||
|
github_checks:
|
||||||
|
annotations: false
|
|
@ -133,6 +133,8 @@ func (b *Buffer) AddUpdate(o types.SliceOrderBook, firstUpdateID int64, finalArg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) fetchAndPush() error {
|
func (b *Buffer) fetchAndPush() error {
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
book, finalUpdateID, err := b.fetcher()
|
book, finalUpdateID, err := b.fetcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -140,9 +142,6 @@ func (b *Buffer) fetchAndPush() error {
|
||||||
|
|
||||||
log.Debugf("fetched depth snapshot, final update id %d", finalUpdateID)
|
log.Debugf("fetched depth snapshot, final update id %d", finalUpdateID)
|
||||||
|
|
||||||
b.mu.Lock()
|
|
||||||
defer b.mu.Unlock()
|
|
||||||
|
|
||||||
if len(b.buffer) > 0 {
|
if len(b.buffer) > 0 {
|
||||||
// the snapshot is too early
|
// the snapshot is too early
|
||||||
if finalUpdateID < b.buffer[0].FirstUpdateID {
|
if finalUpdateID < b.buffer[0].FirstUpdateID {
|
||||||
|
|
|
@ -23,6 +23,7 @@ func TestDepthBuffer_ReadyState(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, 33, nil
|
}, 33, nil
|
||||||
})
|
})
|
||||||
|
buf.SetBufferingPeriod(time.Millisecond * 5)
|
||||||
|
|
||||||
readyC := make(chan struct{})
|
readyC := make(chan struct{})
|
||||||
buf.OnReady(func(snapshot types.SliceOrderBook, updates []Update) {
|
buf.OnReady(func(snapshot types.SliceOrderBook, updates []Update) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -10,14 +11,19 @@ import (
|
||||||
func TestReonce_DoAndReset(t *testing.T) {
|
func TestReonce_DoAndReset(t *testing.T) {
|
||||||
var cnt = 0
|
var cnt = 0
|
||||||
var reonce Reonce
|
var reonce Reonce
|
||||||
|
var wgAll, wg sync.WaitGroup
|
||||||
|
wg.Add(1)
|
||||||
|
wgAll.Add(2)
|
||||||
go reonce.Do(func() {
|
go reonce.Do(func() {
|
||||||
t.Log("once #1")
|
t.Log("once #1")
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
cnt++
|
cnt++
|
||||||
|
wg.Done()
|
||||||
|
wgAll.Done()
|
||||||
})
|
})
|
||||||
|
|
||||||
// make sure it's locked
|
// make sure it's locked
|
||||||
time.Sleep(10 * time.Millisecond)
|
wg.Wait()
|
||||||
t.Logf("reset")
|
t.Logf("reset")
|
||||||
reonce.Reset()
|
reonce.Reset()
|
||||||
|
|
||||||
|
@ -25,8 +31,9 @@ func TestReonce_DoAndReset(t *testing.T) {
|
||||||
t.Log("once #2")
|
t.Log("once #2")
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
cnt++
|
cnt++
|
||||||
|
wgAll.Done()
|
||||||
})
|
})
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
wgAll.Wait()
|
||||||
assert.Equal(t, 2, cnt)
|
assert.Equal(t, 2, cnt)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user