From c1e1fb5933a48775cceeeaa4a124b400be00dd6d Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 28 Feb 2014 23:50:42 +0800 Subject: [PATCH] fixed tests --- cache_test.go | 7 ++++--- item.go | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cache_test.go b/cache_test.go index f62e16c..a18f88f 100644 --- a/cache_test.go +++ b/cache_test.go @@ -7,7 +7,7 @@ import ( "time" ) -func TestGCsTheOldestItems(t *testing.T) { +func TestCacheGCsTheOldestItems(t *testing.T) { spec := gspec.New(t) cache := New(Configure().ItemsToPrune(10)) for i := 0; i < 500; i++ { @@ -18,12 +18,13 @@ func TestGCsTheOldestItems(t *testing.T) { spec.Expect(cache.Get("10").(int)).ToEqual(10) } -func TestPromotedItemsDontGetPruned(t *testing.T) { +func TestCachePromotedItemsDontGetPruned(t *testing.T) { spec := gspec.New(t) cache := New(Configure().ItemsToPrune(10).GetsPerPromote(1)) for i := 0; i < 500; i++ { cache.Set(strconv.Itoa(i), i, time.Minute) } + time.Sleep(time.Millisecond * 10) //run the worker once to init the list cache.Get("9") time.Sleep(time.Millisecond * 10) cache.gc() @@ -32,7 +33,7 @@ func TestPromotedItemsDontGetPruned(t *testing.T) { spec.Expect(cache.Get("11").(int)).ToEqual(11) } -func TestTrackerDoesNotCleanupHeldInstance(t *testing.T) { +func TestCacheTrackerDoesNotCleanupHeldInstance(t *testing.T) { spec := gspec.New(t) cache := New(Configure().ItemsToPrune(10).Track()) for i := 0; i < 10; i++ { diff --git a/item.go b/item.go index 80c1028..e08788b 100644 --- a/item.go +++ b/item.go @@ -39,6 +39,7 @@ func newItem(key string, value interface{}, expires time.Time) *Item { } func (i *Item) shouldPromote(getsPerPromote int32) bool { + println(atomic.LoadInt32(&i.promotions)) return atomic.AddInt32(&i.promotions, 1) == getsPerPromote }