Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Change additional cache test to use chrono
Browse files Browse the repository at this point in the history
  • Loading branch information
nqn committed Nov 17, 2015
1 parent 200e817 commit b9cccfd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions control/plugin/client/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ func TestCache(t *testing.T) {
So(ret, ShouldBeNil)
})
Convey("returns nil if the cache cell has expired", t, func() {
// Make sure global clock is restored after test.
defer chrono.Chrono.Reset()
defer chrono.Chrono.Continue()

// Use artificial time: pause to get base time.
chrono.Chrono.Pause()

mc := &cache{
table: make(map[string]*cachecell),
}
foo := &plugin.PluginMetricType{
Namespace_: []string{"foo", "bar"},
}
mc.put("/foo/bar", 1, foo)
time.Sleep(301 * time.Millisecond)
chrono.Chrono.Forward(301 * time.Millisecond)

ret := mc.get("/foo/bar", 1)
So(ret, ShouldBeNil)
Expand All @@ -77,11 +84,9 @@ func TestCache(t *testing.T) {
So(mc.table["/foo/bar:1"].hits, ShouldEqual, 1)
})
Convey("ticks miss count when a cache entry is still a hit", func() {
// Make sure global clock is restored after test.
defer chrono.Chrono.Reset()
defer chrono.Chrono.Continue()

// Use artificial time: pause to get base time.
chrono.Chrono.Pause()

mc := &cache{
Expand Down

0 comments on commit b9cccfd

Please sign in to comment.