fixed tests

This commit is contained in:
Karl Seguin 2014-02-28 23:50:42 +08:00
parent 890bb18dbf
commit c1e1fb5933
2 changed files with 5 additions and 3 deletions

View file

@ -7,7 +7,7 @@ import (
"time" "time"
) )
func TestGCsTheOldestItems(t *testing.T) { func TestCacheGCsTheOldestItems(t *testing.T) {
spec := gspec.New(t) spec := gspec.New(t)
cache := New(Configure().ItemsToPrune(10)) cache := New(Configure().ItemsToPrune(10))
for i := 0; i < 500; i++ { for i := 0; i < 500; i++ {
@ -18,12 +18,13 @@ func TestGCsTheOldestItems(t *testing.T) {
spec.Expect(cache.Get("10").(int)).ToEqual(10) spec.Expect(cache.Get("10").(int)).ToEqual(10)
} }
func TestPromotedItemsDontGetPruned(t *testing.T) { func TestCachePromotedItemsDontGetPruned(t *testing.T) {
spec := gspec.New(t) spec := gspec.New(t)
cache := New(Configure().ItemsToPrune(10).GetsPerPromote(1)) cache := New(Configure().ItemsToPrune(10).GetsPerPromote(1))
for i := 0; i < 500; i++ { for i := 0; i < 500; i++ {
cache.Set(strconv.Itoa(i), i, time.Minute) cache.Set(strconv.Itoa(i), i, time.Minute)
} }
time.Sleep(time.Millisecond * 10) //run the worker once to init the list
cache.Get("9") cache.Get("9")
time.Sleep(time.Millisecond * 10) time.Sleep(time.Millisecond * 10)
cache.gc() cache.gc()
@ -32,7 +33,7 @@ func TestPromotedItemsDontGetPruned(t *testing.T) {
spec.Expect(cache.Get("11").(int)).ToEqual(11) spec.Expect(cache.Get("11").(int)).ToEqual(11)
} }
func TestTrackerDoesNotCleanupHeldInstance(t *testing.T) { func TestCacheTrackerDoesNotCleanupHeldInstance(t *testing.T) {
spec := gspec.New(t) spec := gspec.New(t)
cache := New(Configure().ItemsToPrune(10).Track()) cache := New(Configure().ItemsToPrune(10).Track())
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {

View file

@ -39,6 +39,7 @@ func newItem(key string, value interface{}, expires time.Time) *Item {
} }
func (i *Item) shouldPromote(getsPerPromote int32) bool { func (i *Item) shouldPromote(getsPerPromote int32) bool {
println(atomic.LoadInt32(&i.promotions))
return atomic.AddInt32(&i.promotions, 1) == getsPerPromote return atomic.AddInt32(&i.promotions, 1) == getsPerPromote
} }