From a9810996525e37d9fed695fd95ffdcfd77ebafd0 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Tue, 3 Mar 2020 00:04:39 +0530 Subject: [PATCH] Add error checks to TestUnlinkGroupTeam (#13956) I could not figure out the actual root cause for this. But a possible area of concern is that somewhere in the call stack, the login failed partially. Therefore, the session did not have the teamMembers populated. And the permission check failed therefore. Adding the error checks should let us know in future if this is not the case. Another possible case is the app.ClearTeamMembersCache which gets called in the goroutine app.SyncRolesAndMembership. If this races with the session, then it's possible that the teamMember is wiped off from the session. But this happens after the permission check. So it's not very likely. Also, while we are here, I found that (*app).ClearTeamMembersCache does not log the internal error bubbled up. This prevents us from understanding what actually happened. Added that logging. --- api4/group_test.go | 8 +++++--- app/team.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api4/group_test.go b/api4/group_test.go index 611159525d..a7ef53f265 100644 --- a/api4/group_test.go +++ b/api4/group_test.go @@ -236,10 +236,12 @@ func TestUnlinkGroupTeam(t *testing.T) { response = th.Client.UnlinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam) assert.NotNil(t, response.Error) - th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam) - th.Client.Logout() - th.Client.Login(th.BasicUser.Email, th.BasicUser.Password) + ok, response := th.Client.Logout() + assert.True(t, ok) + CheckOKStatus(t, response) + _, response = th.Client.Login(th.BasicUser.Email, th.BasicUser.Password) + CheckOKStatus(t, response) response = th.Client.UnlinkGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam) CheckOKStatus(t, response) diff --git a/app/team.go b/app/team.go index d19faad8ba..8f83664b7c 100644 --- a/app/team.go +++ b/app/team.go @@ -1602,7 +1602,7 @@ func (a *App) ClearTeamMembersCache(teamID string) { for { teamMembers, err := a.Srv().Store.Team().GetMembers(teamID, page, perPage, &model.ViewUsersRestrictions{}) if err != nil { - a.Log().Warn("error clearing cache for team members", mlog.String("team_id", teamID)) + a.Log().Warn("error clearing cache for team members", mlog.String("team_id", teamID), mlog.String("err", err.Error())) break }