diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 44d4010fd..cbdedb2ef 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -16,7 +16,7 @@ }, { "ImportPath": "github.com/jonboulle/clockwork", - "Rev": "46fde511e4fda2f685792de1700f20e1c45bfe41" + "Rev": "72f9bd7c4e0c2a40055ab3d0f09654f730cce982" }, { "ImportPath": "github.com/stretchr/testify/assert", diff --git a/Godeps/_workspace/src/github.com/jonboulle/clockwork/README.md b/Godeps/_workspace/src/github.com/jonboulle/clockwork/README.md index 99823200f..236c86a24 100644 --- a/Godeps/_workspace/src/github.com/jonboulle/clockwork/README.md +++ b/Godeps/_workspace/src/github.com/jonboulle/clockwork/README.md @@ -39,8 +39,8 @@ func TestMyFunc(t *testing.T) { assert_state() - // Tick the FakeClock forward in time - c.Tick(3) + // Advance the FakeClock forward in time + c.Advance(3) assert_state() } diff --git a/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork.go b/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork.go index e2ea72ba9..4b6918b52 100644 --- a/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork.go +++ b/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork.go @@ -14,12 +14,12 @@ type Clock interface { } // FakeClock provides an interface for a clock which can be -// manually ticked through time +// manually advanced through time type FakeClock interface { Clock - // Tick advances the FakeClock to a new point in time, ensuring any existing + // Advance advances the FakeClock to a new point in time, ensuring any existing // sleepers are notified appropriately before returning - Tick(d time.Duration) + Advance(d time.Duration) // BlockUntil will block until the FakeClock has the given number of // sleepers (callers of Sleep or After) BlockUntil(n int) @@ -32,7 +32,7 @@ func NewRealClock() Clock { } // NewFakeClock returns a FakeClock implementation which can be -// manually ticked through time for testing. +// manually advanced through time for testing. func NewFakeClock() FakeClock { return &fakeClock{ l: sync.RWMutex{}, @@ -122,10 +122,11 @@ func (fc *fakeClock) Now() time.Time { return fc.time } -// Tick advances fakeClock to a new point in time, ensuring channels from any +// Advance advances fakeClock to a new point in time, ensuring channels from any // previous invocations of After are notified appropriately before returning -func (fc *fakeClock) Tick(d time.Duration) { +func (fc *fakeClock) Advance(d time.Duration) { fc.l.Lock() + defer fc.l.Unlock() end := fc.time.Add(d) var newSleepers []*sleeper for _, s := range fc.sleepers { @@ -138,7 +139,6 @@ func (fc *fakeClock) Tick(d time.Duration) { fc.sleepers = newSleepers fc.blockers = notifyBlockers(fc.blockers, len(fc.sleepers)) fc.time = end - fc.l.Unlock() } // BlockUntil will block until the fakeClock has the given number of sleepers diff --git a/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork_test.go b/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork_test.go index a37eb9138..95f886632 100644 --- a/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork_test.go +++ b/Godeps/_workspace/src/github.com/jonboulle/clockwork/clockwork_test.go @@ -18,7 +18,7 @@ func TestFakeClockAfter(t *testing.T) { two := fc.After(2) six := fc.After(6) ten := fc.After(10) - fc.Tick(1) + fc.Advance(1) select { case <-one: default: @@ -33,7 +33,7 @@ func TestFakeClockAfter(t *testing.T) { t.Errorf("ten returned prematurely!") default: } - fc.Tick(1) + fc.Advance(1) select { case <-two: default: @@ -46,7 +46,7 @@ func TestFakeClockAfter(t *testing.T) { t.Errorf("ten returned prematurely!") default: } - fc.Tick(1) + fc.Advance(1) select { case <-six: t.Errorf("six returned prematurely!") @@ -54,7 +54,7 @@ func TestFakeClockAfter(t *testing.T) { t.Errorf("ten returned prematurely!") default: } - fc.Tick(3) + fc.Advance(3) select { case <-six: default: @@ -65,7 +65,7 @@ func TestFakeClockAfter(t *testing.T) { t.Errorf("ten returned prematurely!") default: } - fc.Tick(100) + fc.Advance(100) select { case <-ten: default: diff --git a/Godeps/_workspace/src/github.com/jonboulle/clockwork/example_test.go b/Godeps/_workspace/src/github.com/jonboulle/clockwork/example_test.go index fb58a7388..6a41bd86b 100644 --- a/Godeps/_workspace/src/github.com/jonboulle/clockwork/example_test.go +++ b/Godeps/_workspace/src/github.com/jonboulle/clockwork/example_test.go @@ -38,8 +38,8 @@ func TestMyFunc(t *testing.T) { // Assert the initial state assert_state(t, i, 0) - // Now tick the clock forward in time - c.Tick(1 * time.Hour) + // Now advance the clock forward in time + c.Advance(1 * time.Hour) // Wait until the function completes wg.Wait() diff --git a/discovery/discovery.go b/discovery/discovery.go index 1c7af396a..d20a5b1b0 100644 --- a/discovery/discovery.go +++ b/discovery/discovery.go @@ -13,8 +13,8 @@ import ( "strings" "time" - "github.com/coreos/etcd/client" "github.com/coreos/etcd/Godeps/_workspace/src/github.com/jonboulle/clockwork" + "github.com/coreos/etcd/client" ) var ( diff --git a/discovery/discovery_test.go b/discovery/discovery_test.go index 5496240c6..77363db6b 100644 --- a/discovery/discovery_test.go +++ b/discovery/discovery_test.go @@ -12,8 +12,8 @@ import ( "testing" "time" - "github.com/coreos/etcd/client" "github.com/coreos/etcd/Godeps/_workspace/src/github.com/jonboulle/clockwork" + "github.com/coreos/etcd/client" ) func TestProxyFuncFromEnvUnset(t *testing.T) { @@ -175,7 +175,7 @@ func TestCheckCluster(t *testing.T) { go func() { for i := uint(1); i <= nRetries; i++ { fc.BlockUntil(1) - fc.Tick(time.Second * (0x1 << i)) + fc.Advance(time.Second * (0x1 << i)) } }() ns, size, err := d.checkCluster() @@ -263,7 +263,7 @@ func TestWaitNodes(t *testing.T) { go func() { for i := uint(1); i <= nRetries; i++ { fc.BlockUntil(1) - fc.Tick(time.Second * (0x1 << i)) + fc.Advance(time.Second * (0x1 << i)) } }() g, err := d.waitNodes(tt.nodes, 3) @@ -363,7 +363,7 @@ func TestRetryFailure(t *testing.T) { go func() { for i := uint(1); i <= nRetries; i++ { fc.BlockUntil(1) - fc.Tick(time.Second * (0x1 << i)) + fc.Advance(time.Second * (0x1 << i)) } }() if _, _, err := d.checkCluster(); err != ErrTooManyRetries { diff --git a/etcdserver/etcdhttp/http_test.go b/etcdserver/etcdhttp/http_test.go index 4813003fc..c50e1818f 100644 --- a/etcdserver/etcdhttp/http_test.go +++ b/etcdserver/etcdhttp/http_test.go @@ -217,7 +217,7 @@ func TestBadParseRequest(t *testing.T) { func TestGoodParseRequest(t *testing.T) { fc := clockwork.NewFakeClock() - fc.Tick(1111) + fc.Advance(1111) tests := []struct { in *http.Request w etcdserverpb.Request diff --git a/store/stats_test.go b/store/stats_test.go index a292a2467..e12f12d6c 100644 --- a/store/stats_test.go +++ b/store/stats_test.go @@ -93,7 +93,7 @@ func TestStoreStatsExpireCount(t *testing.T) { s.Create("/foo", false, "bar", false, fc.Now().Add(500*time.Millisecond)) assert.Equal(t, uint64(0), s.Stats.ExpireCount, "") - fc.Tick(600 * time.Millisecond) + fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) assert.Equal(t, uint64(1), s.Stats.ExpireCount, "") } diff --git a/store/store_test.go b/store/store_test.go index 17677cfb1..f873f0a9f 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -323,7 +323,7 @@ func TestStoreUpdateValueTTL(t *testing.T) { e, _ := s.Get("/foo", false, false) assert.Equal(t, *e.Node.Value, "baz", "") assert.Equal(t, e.EtcdIndex, eidx, "") - fc.Tick(600 * time.Millisecond) + fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) e, err = s.Get("/foo", false, false) assert.Nil(t, e, "") @@ -346,7 +346,7 @@ func TestStoreUpdateDirTTL(t *testing.T) { assert.Equal(t, *e.Node.Value, "baz", "") assert.Equal(t, e.EtcdIndex, eidx, "") - fc.Tick(600 * time.Millisecond) + fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) e, err = s.Get("/foo/bar", false, false) assert.Nil(t, e, "") @@ -715,7 +715,7 @@ func TestStoreWatchExpire(t *testing.T) { c := w.EventChan() e := nbselect(c) assert.Nil(t, e, "") - fc.Tick(600 * time.Millisecond) + fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) eidx = 3 e = nbselect(c) @@ -800,7 +800,7 @@ func TestStoreRecoverWithExpiration(t *testing.T) { s2.Recovery(b) - fc.Tick(600 * time.Millisecond) + fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) e, err := s.Get("/foo/x", false, false) @@ -904,11 +904,11 @@ func TestStoreWatchExpireWithHiddenKey(t *testing.T) { c := w.EventChan() e := nbselect(c) assert.Nil(t, e, "") - fc.Tick(600 * time.Millisecond) + fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) e = nbselect(c) assert.Nil(t, e, "") - fc.Tick(600 * time.Millisecond) + fc.Advance(600 * time.Millisecond) s.DeleteExpiredKeys(fc.Now()) e = nbselect(c) assert.Equal(t, e.Action, "expire", "")