mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/wait: don't expect time.Now() to be strict increasing in WaitTime tests
This commit is contained in:
parent
30cf8b7f0f
commit
f9d122066e
@ -42,16 +42,11 @@ func NewTimeList() *timeList {
|
||||
func (tl *timeList) Wait(deadline time.Time) <-chan struct{} {
|
||||
tl.l.Lock()
|
||||
defer tl.l.Unlock()
|
||||
ch := make(chan struct{}, 1)
|
||||
// The given deadline SHOULD be unique but CI manages to get
|
||||
// the same nano time in the unit tests.
|
||||
nano := deadline.UnixNano()
|
||||
for {
|
||||
if tl.m[nano] == nil {
|
||||
tl.m[nano] = ch
|
||||
break
|
||||
}
|
||||
nano++
|
||||
ch := tl.m[nano]
|
||||
if ch == nil {
|
||||
ch = make(chan struct{})
|
||||
tl.m[nano] = ch
|
||||
}
|
||||
return ch
|
||||
}
|
||||
|
@ -21,28 +21,28 @@ import (
|
||||
|
||||
func TestWaitTime(t *testing.T) {
|
||||
wt := NewTimeList()
|
||||
ch1 := wt.Wait(time.Now())
|
||||
t1 := time.Now()
|
||||
wt.Trigger(t1)
|
||||
ch1 := wt.Wait(t1)
|
||||
wt.Trigger(time.Unix(0, t1.UnixNano()+1))
|
||||
select {
|
||||
case <-ch1:
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
default:
|
||||
t.Fatalf("cannot receive from ch as expected")
|
||||
}
|
||||
|
||||
ch2 := wt.Wait(time.Now())
|
||||
t2 := time.Now()
|
||||
wt.Trigger(t1)
|
||||
select {
|
||||
case <-ch2:
|
||||
t.Fatalf("unexpected to receive from ch")
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
}
|
||||
ch2 := wt.Wait(t2)
|
||||
wt.Trigger(t2)
|
||||
select {
|
||||
case <-ch2:
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
t.Fatalf("cannot receive from ch as expected")
|
||||
t.Fatalf("unexpected to receive from ch2")
|
||||
default:
|
||||
}
|
||||
wt.Trigger(time.Unix(0, t2.UnixNano()+1))
|
||||
select {
|
||||
case <-ch2:
|
||||
default:
|
||||
t.Fatalf("cannot receive from ch2 as expected")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user