Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 committed Sep 20, 2023
1 parent cae0f07 commit 53554b1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/election/storage_orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func (s *ORMStorage) create(ctx context.Context, record *Record) error {
})
}

func (s *ORMStorage) TxnWithLeaderCheck(ctx context.Context, leaderID string, fc func(tx *gorm.DB) error) error {
// TxnWithLeaderLock execute a transaction with leader row locked.
func (s *ORMStorage) TxnWithLeaderLock(ctx context.Context, leaderID string, fc func(tx *gorm.DB) error) error {
return s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
var do DO
ret := tx.Select("leader_id").Where("id = ? and leader_id = ?", leaderRowID, leaderID).
Expand Down
4 changes: 2 additions & 2 deletions pkg/election/storage_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestORMStorageTxnWithLeaderCheck(t *testing.T) {
doNothing := func(*gorm.DB) error {
return nil
}
err := s.TxnWithLeaderCheck(context.Background(), "leader1", doNothing)
err := s.TxnWithLeaderLock(context.Background(), "leader1", doNothing)
require.ErrorIs(t, err, errors.ErrElectorNotLeader)

mock.ExpectBegin()
Expand All @@ -223,6 +223,6 @@ func TestORMStorageTxnWithLeaderCheck(t *testing.T) {
require.NoError(t, err)
return nil
}
err = s.TxnWithLeaderCheck(context.Background(), "leader1", doTxn)
err = s.TxnWithLeaderLock(context.Background(), "leader1", doTxn)
require.NoError(t, err)
}

0 comments on commit 53554b1

Please sign in to comment.