mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-27040: Fix flaky tests due to same UpdateAt timestamp (#15216)
* MM-27040: Fix flaky tests due to same UpdateAt timestamp
Update queries are not guaranteed to always update the row.
Since we are only bumping the UpdateAt timestamps, if 2 update
requests hit concurrently within the same millisecond, then one
is bound to fail.
We fix all cases in the codebase where we were updating the UpdateAt
field to not check for count != 1, but rather count > 1.
A similar fix was already done in 3f46cf6f60.
* Remove incorrect test
This commit is contained in:
@@ -205,7 +205,7 @@ func (us SqlBotStore) Update(bot *model.Bot) (*model.Bot, error) {
|
||||
|
||||
if count, err := us.GetMaster().Update(botFromModel(bot)); err != nil {
|
||||
return nil, errors.Wrapf(err, "update: user_id=%s", bot.UserId)
|
||||
} else if count != 1 {
|
||||
} else if count > 1 {
|
||||
return nil, fmt.Errorf("unexpected count while updating bot: count=%d, userId=%s", count, bot.UserId)
|
||||
}
|
||||
|
||||
|
||||
@@ -907,8 +907,8 @@ func (s SqlChannelStore) updateChannelT(transaction *gorp.Transaction, channel *
|
||||
return nil, errors.Wrapf(err, "failed to update channel with id=%s", channel.Id)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
return nil, fmt.Errorf("the expected number of channels to be updated is 1 but was %d", count)
|
||||
if count > 1 {
|
||||
return nil, fmt.Errorf("the expected number of channels to be updated is <=1 but was %d", count)
|
||||
}
|
||||
|
||||
return channel, nil
|
||||
|
||||
@@ -100,7 +100,7 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update OAuthApp with id=%s", app.Id)
|
||||
}
|
||||
if count != 1 {
|
||||
if count > 1 {
|
||||
return nil, store.NewErrInvalidInput("OAuthApp", "Id", app.Id)
|
||||
}
|
||||
return app, nil
|
||||
|
||||
@@ -296,7 +296,7 @@ func (s SqlTeamStore) Update(team *model.Team) (*model.Team, *model.AppError) {
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.updating.app_error", nil, "id="+team.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if count != 1 {
|
||||
if count > 1 {
|
||||
return nil, model.NewAppError("SqlTeamStore.Update", "store.sql_team.update.app_error", nil, "id="+team.Id, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) (*model.
|
||||
return nil, model.NewAppError("SqlUserStore.Update", "store.sql_user.update.updating.app_error", nil, "user_id="+user.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
if count > 1 {
|
||||
return nil, model.NewAppError("SqlUserStore.Update", "store.sql_user.update.app_error", nil, fmt.Sprintf("user_id=%v, count=%v", user.Id, count), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
@@ -304,10 +304,6 @@ func testChannelStoreUpdate(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Channel().Update(&o1)
|
||||
require.NotNil(t, err, "Update should have failed because of missing key")
|
||||
|
||||
o1.Id = model.NewId()
|
||||
_, err = ss.Channel().Update(&o1)
|
||||
require.NotNil(t, err, "update should have failed because id change")
|
||||
|
||||
o2.Name = o1.Name
|
||||
_, err = ss.Channel().Update(&o2)
|
||||
require.NotNil(t, err, "update should have failed because of existing name")
|
||||
|
||||
Reference in New Issue
Block a user