summaryrefslogtreecommitdiffstats
path: root/store/storetest
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2018-02-09 17:47:22 -0500
committerChristopher Speller <crspeller@gmail.com>2018-02-09 14:47:22 -0800
commit3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6 (patch)
tree7623b855717697cbc4b7b45ab47f5c35c76b8c9c /store/storetest
parent0daac7e4fc05ecb64dbc162daff618569bb249cd (diff)
downloadchat-3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6.tar.gz
chat-3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6.tar.bz2
chat-3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6.zip
ABC-228 Update GetPosts caching to work for non-60 limits (#8233)
* Update GetPosts caching to work for non-60 limits * Only cache on limits of 30/60 and add test * Add comments clarifying 30 and 60 limits
Diffstat (limited to 'store/storetest')
-rw-r--r--store/storetest/post_store.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go
index 4deb7f8d4..e663d5a41 100644
--- a/store/storetest/post_store.go
+++ b/store/storetest/post_store.go
@@ -27,7 +27,7 @@ func TestPostStore(t *testing.T, ss store.Store) {
t.Run("PermDelete1Level", func(t *testing.T) { testPostStorePermDelete1Level(t, ss) })
t.Run("PermDelete1Level2", func(t *testing.T) { testPostStorePermDelete1Level2(t, ss) })
t.Run("GetWithChildren", func(t *testing.T) { testPostStoreGetWithChildren(t, ss) })
- t.Run("GetPostsWtihDetails", func(t *testing.T) { testPostStoreGetPostsWtihDetails(t, ss) })
+ t.Run("GetPostsWithDetails", func(t *testing.T) { testPostStoreGetPostsWithDetails(t, ss) })
t.Run("GetPostsBeforeAfter", func(t *testing.T) { testPostStoreGetPostsBeforeAfter(t, ss) })
t.Run("GetPostsSince", func(t *testing.T) { testPostStoreGetPostsSince(t, ss) })
t.Run("Search", func(t *testing.T) { testPostStoreSearch(t, ss) })
@@ -490,7 +490,7 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
}
}
-func testPostStoreGetPostsWtihDetails(t *testing.T, ss store.Store) {
+func testPostStoreGetPostsWithDetails(t *testing.T, ss store.Store) {
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
@@ -591,6 +591,25 @@ func testPostStoreGetPostsWtihDetails(t *testing.T, ss store.Store) {
if r2.Posts[o1.Id].Message != o1.Message {
t.Fatal("Missing parent")
}
+
+ // Run once to fill cache
+ <-ss.Post().GetPosts(o1.ChannelId, 0, 30, true)
+
+ o6 := &model.Post{}
+ o6.ChannelId = o1.ChannelId
+ o6.UserId = model.NewId()
+ o6.Message = "zz" + model.NewId() + "b"
+ o6 = (<-ss.Post().Save(o6)).Data.(*model.Post)
+
+ // Should only be 6 since we hit the cache
+ r3 := (<-ss.Post().GetPosts(o1.ChannelId, 0, 30, true)).Data.(*model.PostList)
+ assert.Equal(t, 6, len(r3.Order))
+
+ ss.Post().InvalidateLastPostTimeCache(o1.ChannelId)
+
+ // Cache was invalidated, we should get all the posts
+ r4 := (<-ss.Post().GetPosts(o1.ChannelId, 0, 30, true)).Data.(*model.PostList)
+ assert.Equal(t, 7, len(r4.Order))
}
func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {