Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bench number #227

Merged
merged 3 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bench/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ func (t *Task) run(sub SubTasker) {
if !ok {
return
}
default:
//default:

//select里面包含default:会产生一个bug,试问t.Rate如果是很大的值, time.Sleep这句相当于没有
//决定消费者可以消费多少条是消费者自己决定,消费有多块,就可以产生多少令牌给消费者使用
//这和一开始的设计初衷相悖,消费者消费多少条需由t.Number或 t.Duration决定
//注释可以让t.Number 或 t.Duration更准确
}

work <- struct{}{}
Expand Down
1 change: 1 addition & 0 deletions filter/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func Test_Bench_Rate(t *testing.T) {

assert.NoError(t, err)

assert.Equal(t, int32(number), total)
assert.LessOrEqual(t, int64(take), int64(time.Duration(time.Duration(number/rate)*time.Second+100*time.Millisecond)))
assert.GreaterOrEqual(t, int64(take), int64(time.Duration(number/rate)*time.Second-time.Second))
}
Expand Down