about summary refs log tree commit diff stats
path: root/svc/cache_test.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-11 03:58:43 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-11 04:54:50 -0400
commitfdd9bd02f9ec37d25104dce8c1279a007aa980fc (patch)
tree96d5ba15eb81ca84d7b36a9406f50ac4b4042613 /svc/cache_test.go
parent1d9cef515a16602b7dc26b2fe06032b5e731b48e (diff)
downloadgetwtxt-fdd9bd02f9ec37d25104dce8c1279a007aa980fc.tar.gz
cache and db now use time.Ticker for events. refactored some initialization.
Diffstat (limited to 'svc/cache_test.go')
-rw-r--r--svc/cache_test.go54
1 files changed, 5 insertions, 49 deletions
diff --git a/svc/cache_test.go b/svc/cache_test.go
index 29b92b8..28e5c0b 100644
--- a/svc/cache_test.go
+++ b/svc/cache_test.go
@@ -2,76 +2,32 @@ package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
 	"testing"
-	"time"
 )
 
-func Test_cacheTimer(t *testing.T) {
-	initTestConf()
-	dur, _ := time.ParseDuration("5m")
-	back30, _ := time.ParseDuration("-30m")
-
-	cases := []struct {
-		name      string
-		lastCache time.Time
-		interval  time.Duration
-		expect    bool
-	}{
-		{
-			name:      "Past Interval",
-			lastCache: time.Now().Add(back30),
-			interval:  dur,
-			expect:    true,
-		},
-		{
-			name:      "Before Interval",
-			lastCache: time.Now(),
-			interval:  dur,
-			expect:    false,
-		},
-	}
-
-	for _, tt := range cases {
-		t.Run(tt.name, func(t *testing.T) {
-
-			confObj.Mu.Lock()
-			confObj.LastCache = tt.lastCache
-			confObj.CacheInterval = tt.interval
-			confObj.Mu.Unlock()
-
-			res := cacheTimer()
-
-			if res != tt.expect {
-				t.Errorf("Got %v, expected %v\n", res, tt.expect)
-			}
-		})
-	}
-
-}
-
-func Test_refreshCache(t *testing.T) {
+func Test_cacheUpdate(t *testing.T) {
 	initTestConf()
 	confObj.Mu.RLock()
 	prevtime := confObj.LastCache
 	confObj.Mu.RUnlock()
 
 	t.Run("Cache Time Check", func(t *testing.T) {
-		refreshCache()
+		cacheUpdate()
 		confObj.Mu.RLock()
 		newtime := confObj.LastCache
 		confObj.Mu.RUnlock()
 
 		if !newtime.After(prevtime) || newtime == prevtime {
-			t.Errorf("Cache time did not update, check refreshCache() logic\n")
+			t.Errorf("Cache time did not update, check cacheUpdate() logic\n")
 		}
 	})
 }
 
-func Benchmark_refreshCache(b *testing.B) {
+func Benchmark_cacheUpdate(b *testing.B) {
 	initTestConf()
 	b.ResetTimer()
 
 	for i := 0; i < b.N; i++ {
-		refreshCache()
+		cacheUpdate()
 	}
 }