Skip to content

Commit

Permalink
fix: Add retry on locks
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabianoshz committed Oct 12, 2024
1 parent 346a4d8 commit e6d6135
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 269 deletions.
9 changes: 9 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const (
APISecretFlag = "api-secret"
HidePrevPlanComments = "hide-prev-plan-comments"
QuietPolicyChecks = "quiet-policy-checks"
LockAcquireTimeoutSeconds = "lock-acquire-timeout"
LockingDBType = "locking-db-type"
LogLevelFlag = "log-level"
MarkdownTemplateOverridesDirFlag = "markdown-template-overrides-dir"
Expand Down Expand Up @@ -173,6 +174,7 @@ const (
DefaultGiteaBaseURL = "https://gitea.com"
DefaultGiteaPageSize = 30
DefaultGitlabHostname = "gitlab.com"
DefaultLockAcquireTimeoutSeconds = 900
DefaultLockingDBType = "boltdb"
DefaultLogLevel = "info"
DefaultMaxCommentsPerCommand = 100
Expand Down Expand Up @@ -607,6 +609,10 @@ var intFlags = map[string]intFlag{
" If merge base is further behind than this number of commits from any of branches heads, full fetch will be performed.",
defaultValue: DefaultCheckoutDepth,
},
LockAcquireTimeoutSeconds: {
description: fmt.Sprintf("The number of seconds to wait for a lock to be acquired before timing out. The default value is %d", DefaultLockAcquireTimeoutSeconds),
defaultValue: DefaultLockAcquireTimeoutSeconds,
},
MaxCommentsPerCommand: {
description: "If non-zero, the maximum number of comments to split command output into before truncating.",
defaultValue: DefaultMaxCommentsPerCommand,
Expand Down Expand Up @@ -930,6 +936,9 @@ func (s *ServerCmd) setDefaults(c *server.UserConfig, v *viper.Viper) {
if c.AutoDiscoverModeFlag == "" {
c.AutoDiscoverModeFlag = DefaultAutoDiscoverMode
}
if c.LockAcquireTimeoutSeconds == 0 {
c.LockAcquireTimeoutSeconds = DefaultLockAcquireTimeoutSeconds
}
}

func (s *ServerCmd) validate(userConfig server.UserConfig) error {
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
}

defaultTFVersion := terraformClient.DefaultVersion()
locker := events.NewDefaultWorkingDirLocker()
locker := events.NewDefaultWorkingDirLocker(1)
parser := &config.ParserValidator{}

globalCfgArgs := valid.GlobalCfgArgs{
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/locks_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestDeleteLock_UpdateProjectStatus(t *testing.T) {
cp := vcsmocks.NewMockClient()
l := mocks2.NewMockDeleteLockCommand()
workingDir := mocks2.NewMockWorkingDir()
workingDirLocker := events.NewDefaultWorkingDirLocker()
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
pull := models.PullRequest{
BaseRepo: models.Repo{FullName: repoName},
}
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestDeleteLock_CommentFailed(t *testing.T) {
}, nil)
cp := vcsmocks.NewMockClient()
workingDir := mocks2.NewMockWorkingDir()
workingDirLocker := events.NewDefaultWorkingDirLocker()
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
var backend locking.Backend
tmp := t.TempDir()
backend, err := db.New(tmp)
Expand All @@ -372,7 +372,7 @@ func TestDeleteLock_CommentSuccess(t *testing.T) {
cp := vcsmocks.NewMockClient()
dlc := mocks2.NewMockDeleteLockCommand()
workingDir := mocks2.NewMockWorkingDir()
workingDirLocker := events.NewDefaultWorkingDirLocker()
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
var backend locking.Backend
tmp := t.TempDir()
backend, err := db.New(tmp)
Expand Down
2 changes: 1 addition & 1 deletion server/events/delete_lock_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDeleteLock_Success(t *testing.T) {
l := lockmocks.NewMockLocker()
When(l.Unlock("id")).ThenReturn(&models.ProjectLock{}, nil)
workingDir := events.NewMockWorkingDir()
workingDirLocker := events.NewDefaultWorkingDirLocker()
workingDirLocker := events.NewDefaultWorkingDirLocker(1)
workspace := "workspace"
path := "path"
projectName := ""
Expand Down
Loading

0 comments on commit e6d6135

Please sign in to comment.