mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
test stop mockSync goroutines
This commit is contained in:
parent
fe5fb6cfba
commit
811c577fe8
@ -87,7 +87,13 @@ func TestStoreStatsDeleteFail(t *testing.T) {
|
|||||||
//Ensure that the number of expirations is recorded in the stats.
|
//Ensure that the number of expirations is recorded in the stats.
|
||||||
func TestStoreStatsExpireCount(t *testing.T) {
|
func TestStoreStatsExpireCount(t *testing.T) {
|
||||||
s := newStore()
|
s := newStore()
|
||||||
go mockSyncService(s.DeleteExpiredKeys)
|
|
||||||
|
c := make(chan bool)
|
||||||
|
defer func() {
|
||||||
|
c <- true
|
||||||
|
}()
|
||||||
|
|
||||||
|
go mockSyncService(s.DeleteExpiredKeys, c)
|
||||||
s.Create("/foo", "bar", false, time.Now().Add(500*time.Millisecond))
|
s.Create("/foo", "bar", false, time.Now().Add(500*time.Millisecond))
|
||||||
assert.Equal(t, uint64(0), s.Stats.ExpireCount, "")
|
assert.Equal(t, uint64(0), s.Stats.ExpireCount, "")
|
||||||
time.Sleep(600 * time.Millisecond)
|
time.Sleep(600 * time.Millisecond)
|
||||||
|
|||||||
@ -139,7 +139,13 @@ func TestStoreUpdateFailsIfDirectory(t *testing.T) {
|
|||||||
// Ensure that the store can update the TTL on a value.
|
// Ensure that the store can update the TTL on a value.
|
||||||
func TestStoreUpdateValueTTL(t *testing.T) {
|
func TestStoreUpdateValueTTL(t *testing.T) {
|
||||||
s := newStore()
|
s := newStore()
|
||||||
go mockSyncService(s.DeleteExpiredKeys)
|
|
||||||
|
c := make(chan bool)
|
||||||
|
defer func() {
|
||||||
|
c <- true
|
||||||
|
}()
|
||||||
|
go mockSyncService(s.DeleteExpiredKeys, c)
|
||||||
|
|
||||||
s.Create("/foo", "bar", false, Permanent)
|
s.Create("/foo", "bar", false, Permanent)
|
||||||
_, err := s.Update("/foo", "baz", time.Now().Add(500*time.Millisecond))
|
_, err := s.Update("/foo", "baz", time.Now().Add(500*time.Millisecond))
|
||||||
e, _ := s.Get("/foo", false, false)
|
e, _ := s.Get("/foo", false, false)
|
||||||
@ -154,7 +160,13 @@ func TestStoreUpdateValueTTL(t *testing.T) {
|
|||||||
// Ensure that the store can update the TTL on a directory.
|
// Ensure that the store can update the TTL on a directory.
|
||||||
func TestStoreUpdateDirTTL(t *testing.T) {
|
func TestStoreUpdateDirTTL(t *testing.T) {
|
||||||
s := newStore()
|
s := newStore()
|
||||||
go mockSyncService(s.DeleteExpiredKeys)
|
|
||||||
|
c := make(chan bool)
|
||||||
|
defer func() {
|
||||||
|
c <- true
|
||||||
|
}()
|
||||||
|
go mockSyncService(s.DeleteExpiredKeys, c)
|
||||||
|
|
||||||
s.Create("/foo", "", false, Permanent)
|
s.Create("/foo", "", false, Permanent)
|
||||||
s.Create("/foo/bar", "baz", false, Permanent)
|
s.Create("/foo/bar", "baz", false, Permanent)
|
||||||
_, err := s.Update("/foo", "", time.Now().Add(500*time.Millisecond))
|
_, err := s.Update("/foo", "", time.Now().Add(500*time.Millisecond))
|
||||||
@ -339,7 +351,13 @@ func TestStoreWatchRecursiveCompareAndSwap(t *testing.T) {
|
|||||||
// Ensure that the store can watch for key expiration.
|
// Ensure that the store can watch for key expiration.
|
||||||
func TestStoreWatchExpire(t *testing.T) {
|
func TestStoreWatchExpire(t *testing.T) {
|
||||||
s := newStore()
|
s := newStore()
|
||||||
go mockSyncService(s.DeleteExpiredKeys)
|
|
||||||
|
stopChan := make(chan bool)
|
||||||
|
defer func() {
|
||||||
|
stopChan <- true
|
||||||
|
}()
|
||||||
|
go mockSyncService(s.DeleteExpiredKeys, stopChan)
|
||||||
|
|
||||||
s.Create("/foo", "bar", false, time.Now().Add(500*time.Millisecond))
|
s.Create("/foo", "bar", false, time.Now().Add(500*time.Millisecond))
|
||||||
s.Create("/foofoo", "barbarbar", false, time.Now().Add(500*time.Millisecond))
|
s.Create("/foofoo", "barbarbar", false, time.Now().Add(500*time.Millisecond))
|
||||||
|
|
||||||
@ -379,7 +397,13 @@ func TestStoreRecover(t *testing.T) {
|
|||||||
// Ensure that the store can recover from a previously saved state that includes an expiring key.
|
// Ensure that the store can recover from a previously saved state that includes an expiring key.
|
||||||
func TestStoreRecoverWithExpiration(t *testing.T) {
|
func TestStoreRecoverWithExpiration(t *testing.T) {
|
||||||
s := newStore()
|
s := newStore()
|
||||||
go mockSyncService(s.DeleteExpiredKeys)
|
|
||||||
|
c := make(chan bool)
|
||||||
|
defer func() {
|
||||||
|
c <- true
|
||||||
|
}()
|
||||||
|
go mockSyncService(s.DeleteExpiredKeys, c)
|
||||||
|
|
||||||
s.Create("/foo", "", false, Permanent)
|
s.Create("/foo", "", false, Permanent)
|
||||||
s.Create("/foo/x", "bar", false, Permanent)
|
s.Create("/foo/x", "bar", false, Permanent)
|
||||||
s.Create("/foo/y", "baz", false, time.Now().Add(5*time.Millisecond))
|
s.Create("/foo/y", "baz", false, time.Now().Add(5*time.Millisecond))
|
||||||
@ -388,7 +412,13 @@ func TestStoreRecoverWithExpiration(t *testing.T) {
|
|||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
s2 := newStore()
|
s2 := newStore()
|
||||||
go mockSyncService(s2.DeleteExpiredKeys)
|
|
||||||
|
c2 := make(chan bool)
|
||||||
|
defer func() {
|
||||||
|
c2 <- true
|
||||||
|
}()
|
||||||
|
go mockSyncService(s2.DeleteExpiredKeys, c2)
|
||||||
|
|
||||||
s2.Recovery(b)
|
s2.Recovery(b)
|
||||||
|
|
||||||
time.Sleep(600 * time.Millisecond)
|
time.Sleep(600 * time.Millisecond)
|
||||||
@ -412,9 +442,14 @@ func nbselect(c <-chan *Event) *Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mockSyncService(f func(now time.Time)) {
|
func mockSyncService(f func(now time.Time), c chan bool) {
|
||||||
ticker := time.Tick(time.Millisecond * 500)
|
ticker := time.Tick(time.Millisecond * 500)
|
||||||
for now := range ticker {
|
for {
|
||||||
|
select {
|
||||||
|
case <-c:
|
||||||
|
return
|
||||||
|
case now := <-ticker:
|
||||||
f(now)
|
f(now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user