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:
Agniva De Sarker
2020-08-11 21:03:23 +05:30
committed by GitHub
parent e73ff83e9d
commit 3124b81229
6 changed files with 6 additions and 10 deletions

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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")