mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: Speed-up v3compactor unit tests.
The tests were taking ~15s because of 5s wait time in Recorder !?
This commit is contained in:
parent
76e769ce95
commit
0a106754d3
@ -31,8 +31,9 @@ func TestPeriodicHourly(t *testing.T) {
|
||||
retentionDuration := time.Duration(retentionHours) * time.Hour
|
||||
|
||||
fc := clockwork.NewFakeClock()
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStream(), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStream()}
|
||||
// TODO: Do not depand or real time (Recorder.Wait) in unit tests.
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond)}
|
||||
tb := newPeriodic(zap.NewExample(), fc, retentionDuration, rg, compactable)
|
||||
|
||||
tb.Run()
|
||||
@ -82,8 +83,8 @@ func TestPeriodicMinutes(t *testing.T) {
|
||||
retentionDuration := time.Duration(retentionMinutes) * time.Minute
|
||||
|
||||
fc := clockwork.NewFakeClock()
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStream(), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStream()}
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond)}
|
||||
tb := newPeriodic(zap.NewExample(), fc, retentionDuration, rg, compactable)
|
||||
|
||||
tb.Run()
|
||||
@ -130,8 +131,8 @@ func TestPeriodicMinutes(t *testing.T) {
|
||||
func TestPeriodicPause(t *testing.T) {
|
||||
fc := clockwork.NewFakeClock()
|
||||
retentionDuration := time.Hour
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStream(), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStream()}
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond)}
|
||||
tb := newPeriodic(zap.NewExample(), fc, retentionDuration, rg, compactable)
|
||||
|
||||
tb.Run()
|
||||
|
@ -28,8 +28,8 @@ import (
|
||||
|
||||
func TestRevision(t *testing.T) {
|
||||
fc := clockwork.NewFakeClock()
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStream(), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStream()}
|
||||
rg := &fakeRevGetter{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond), 0}
|
||||
compactable := &fakeCompactable{testutil.NewRecorderStreamWithWaitTimout(10 * time.Millisecond)}
|
||||
tb := newRevision(zap.NewExample(), fc, 10, rg, compactable)
|
||||
|
||||
tb.Run()
|
||||
|
@ -82,11 +82,16 @@ func (r *RecorderBuffered) Chan() <-chan Action {
|
||||
|
||||
// RecorderStream writes all Actions to an unbuffered channel
|
||||
type recorderStream struct {
|
||||
ch chan Action
|
||||
ch chan Action
|
||||
waitTimeout time.Duration
|
||||
}
|
||||
|
||||
func NewRecorderStream() Recorder {
|
||||
return &recorderStream{ch: make(chan Action)}
|
||||
return NewRecorderStreamWithWaitTimout(time.Duration(5 * time.Second))
|
||||
}
|
||||
|
||||
func NewRecorderStreamWithWaitTimout(waitTimeout time.Duration) Recorder {
|
||||
return &recorderStream{ch: make(chan Action), waitTimeout: waitTimeout}
|
||||
}
|
||||
|
||||
func (r *recorderStream) Record(a Action) {
|
||||
@ -110,7 +115,7 @@ func (r *recorderStream) Chan() <-chan Action {
|
||||
|
||||
func (r *recorderStream) Wait(n int) ([]Action, error) {
|
||||
acts := make([]Action, n)
|
||||
timeoutC := time.After(5 * time.Second)
|
||||
timeoutC := time.After(r.waitTimeout)
|
||||
for i := 0; i < n; i++ {
|
||||
select {
|
||||
case acts[i] = <-r.ch:
|
||||
|
Loading…
x
Reference in New Issue
Block a user