From 4127474b47731d32f968614ff38249c175d4931c Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 14 Dec 2017 05:37:51 -0600 Subject: fix posts created at test (#7977) --- store/sqlstore/post_store.go | 4 ++-- store/storetest/post_store.go | 15 +++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'store') diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index c60a15ce2..f3305903b 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -1030,10 +1030,10 @@ func (s SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustH func (s SqlPostStore) GetPostsCreatedAt(channelId string, time int64) store.StoreChannel { return store.Do(func(result *store.StoreResult) { - query := `SELECT * FROM Posts WHERE CreateAt = :CreateAt` + query := `SELECT * FROM Posts WHERE CreateAt = :CreateAt AND ChannelId = :ChannelId` var posts []*model.Post - _, err := s.GetReplica().Select(&posts, query, map[string]interface{}{"CreateAt": time}) + _, err := s.GetReplica().Select(&posts, query, map[string]interface{}{"CreateAt": time, "ChannelId": channelId}) if err != nil { result.Err = model.NewAppError("SqlPostStore.GetPostsCreatedAt", "store.sql_post.get_posts_created_att.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError) diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go index afa8ae293..4deb7f8d4 100644 --- a/store/storetest/post_store.go +++ b/store/storetest/post_store.go @@ -1408,7 +1408,7 @@ func testPostStoreGetFlaggedPostsForChannel(t *testing.T, ss store.Store) { } func testPostStoreGetPostsCreatedAt(t *testing.T, ss store.Store) { - createTime := model.GetMillis() + createTime := model.GetMillis() + 1 o0 := &model.Post{} o0.ChannelId = model.NewId() @@ -1418,12 +1418,11 @@ func testPostStoreGetPostsCreatedAt(t *testing.T, ss store.Store) { o0 = (<-ss.Post().Save(o0)).Data.(*model.Post) o1 := &model.Post{} - o1.ChannelId = o0.Id + o1.ChannelId = o0.ChannelId o1.UserId = model.NewId() o1.Message = "zz" + model.NewId() + "b" - o0.CreateAt = createTime + o1.CreateAt = createTime o1 = (<-ss.Post().Save(o1)).Data.(*model.Post) - time.Sleep(2 * time.Millisecond) o2 := &model.Post{} o2.ChannelId = o1.ChannelId @@ -1431,8 +1430,8 @@ func testPostStoreGetPostsCreatedAt(t *testing.T, ss store.Store) { o2.Message = "zz" + model.NewId() + "b" o2.ParentId = o1.Id o2.RootId = o1.Id + o2.CreateAt = createTime + 1 o2 = (<-ss.Post().Save(o2)).Data.(*model.Post) - time.Sleep(2 * time.Millisecond) o3 := &model.Post{} o3.ChannelId = model.NewId() @@ -1440,13 +1439,9 @@ func testPostStoreGetPostsCreatedAt(t *testing.T, ss store.Store) { o3.Message = "zz" + model.NewId() + "b" o3.CreateAt = createTime o3 = (<-ss.Post().Save(o3)).Data.(*model.Post) - time.Sleep(2 * time.Millisecond) r1 := (<-ss.Post().GetPostsCreatedAt(o1.ChannelId, createTime)).Data.([]*model.Post) - - if len(r1) != 2 { - t.Fatalf("Got the wrong number of posts.") - } + assert.Equal(t, 2, len(r1)) } func testPostStoreOverwrite(t *testing.T, ss store.Store) { -- cgit v1.2.3-1-g7c22