summaryrefslogtreecommitdiffstats
path: root/store/sql_post_store_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-12-13 22:24:24 -0500
committerenahum <nahumhbl@gmail.com>2016-12-14 00:24:24 -0300
commit86fb0d87a3a09b237bec124ce0e74cd05aa164be (patch)
treedab6753888596cc2ba8df8c273ced364bff6b26d /store/sql_post_store_test.go
parent2e58f7504b79fc85d43468ffa06954a23221ea32 (diff)
downloadchat-86fb0d87a3a09b237bec124ce0e74cd05aa164be.tar.gz
chat-86fb0d87a3a09b237bec124ce0e74cd05aa164be.tar.bz2
chat-86fb0d87a3a09b237bec124ce0e74cd05aa164be.zip
Adding caching layer to some posts calls (#4779)
Diffstat (limited to 'store/sql_post_store_test.go')
-rw-r--r--store/sql_post_store_test.go43
1 files changed, 39 insertions, 4 deletions
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index d685ea41e..30376fae5 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -37,14 +37,14 @@ func TestPostStoreGet(t *testing.T) {
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
- etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
+ etag1 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
t.Fatal("Invalid Etag")
}
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
- etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
+ etag2 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
t.Fatal("Invalid Etag")
}
@@ -62,6 +62,41 @@ func TestPostStoreGet(t *testing.T) {
}
}
+func TestGetEtagCache(t *testing.T) {
+ Setup()
+ o1 := &model.Post{}
+ o1.ChannelId = model.NewId()
+ o1.UserId = model.NewId()
+ o1.Message = "a" + model.NewId() + "b"
+
+ etag1 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
+ if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
+ t.Fatal("Invalid Etag")
+ }
+
+ // This one should come from the cache
+ etag2 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
+ if strings.Index(etag2, model.CurrentVersion+".0.") != 0 {
+ t.Fatal("Invalid Etag")
+ }
+
+ o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
+
+ // We have not invalidated the cache so this should be the same as above
+ etag3 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
+ if strings.Index(etag3, model.CurrentVersion+".0.") != 0 {
+ t.Fatal("Invalid Etag")
+ }
+
+ store.Post().InvalidatePostEtagCache(o1.ChannelId)
+
+ // Invalidated cache so we should get a good result
+ etag4 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
+ if strings.Index(etag4, model.CurrentVersion+"."+o1.Id) != 0 {
+ t.Fatal("Invalid Etag")
+ }
+}
+
func TestPostStoreUpdate(t *testing.T) {
Setup()
@@ -164,7 +199,7 @@ func TestPostStoreDelete(t *testing.T) {
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
- etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
+ etag1 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
t.Fatal("Invalid Etag")
}
@@ -188,7 +223,7 @@ func TestPostStoreDelete(t *testing.T) {
t.Fatal("Missing id should have failed")
}
- etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string)
+ etag2 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
t.Fatal("Invalid Etag")
}