From 66d174d80b3277421311b9a79aead6c6ba513564 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Wed, 9 Jan 2019 14:01:24 -0500 Subject: [PATCH] Fix various unit tests (#10079) * fix spurious TestMuteCommandSpecificChannel test failure See https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw * fix race in TestExportUserChannels * TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway --- app/channel.go | 2 +- app/command_mute_test.go | 2 -- app/export_test.go | 8 ++------ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/channel.go b/app/channel.go index 61401ac2c3..d9e4d7533d 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1790,7 +1790,7 @@ func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelM member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION } - a.Srv.Store.Channel().UpdateMember(member) + <-a.Srv.Store.Channel().UpdateMember(member) return member } diff --git a/app/command_mute_test.go b/app/command_mute_test.go index 6a2e9d775b..4551dfa960 100644 --- a/app/command_mute_test.go +++ b/app/command_mute_test.go @@ -99,7 +99,6 @@ func TestMuteCommandSpecificChannel(t *testing.T) { UserId: th.BasicUser.Id, }, channel2.Name) assert.Equal(t, "api.command_mute.success_mute", resp.Text) - time.Sleep(time.Millisecond) channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id) assert.Equal(t, model.CHANNEL_NOTIFY_MENTION, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP]) @@ -111,7 +110,6 @@ func TestMuteCommandSpecificChannel(t *testing.T) { }, "~"+channel2.Name) assert.Equal(t, "api.command_mute.success_unmute", resp.Text) - time.Sleep(time.Millisecond) channel2M, _ = th.App.GetChannelMember(channel2.Id, th.BasicUser.Id) assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP]) } diff --git a/app/export_test.go b/app/export_test.go index 551e4ec0e3..771a98148d 100644 --- a/app/export_test.go +++ b/app/export_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/store" "github.com/stretchr/testify/require" ) @@ -78,12 +79,7 @@ func TestExportUserChannels(t *testing.T) { } var preferences model.Preferences preferences = append(preferences, preference) - channelMember := model.ChannelMember{ - ChannelId: channel.Id, - UserId: user.Id, - } - th.App.Srv.Store.Channel().SaveMember(&channelMember) - th.App.Srv.Store.Preference().Save(&preferences) + store.Must(th.App.Srv.Store.Preference().Save(&preferences)) th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id) exportData, err := th.App.buildUserChannelMemberships(user.Id, team.Id) require.Nil(t, err)