Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add Close Calls to BoltDB Tests to fix Windows Test Errors #5289

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/core/db/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,7 @@ func (b *BoltDB) projectResultToProject(p command.ProjectResult) models.ProjectS
Status: p.PlanStatus(),
}
}

func (b *BoltDB) Close() error {
return b.db.Close()
}
8 changes: 7 additions & 1 deletion server/core/db/boltdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ func TestPullStatus_UpdateGet(t *testing.T) {
Status: models.ErroredPlanStatus,
},
}, status.Projects)
b.Close()
}

// Test we can create a status, delete it, and then we shouldn't be able to getCommandLock
Expand Down Expand Up @@ -533,6 +534,7 @@ func TestPullStatus_UpdateDeleteGet(t *testing.T) {
maybeStatus, err := b.GetPullStatus(pull)
Ok(t, err)
Assert(t, maybeStatus == nil, "exp nil")
b.Close()
}

// Test we can create a status, update a specific project's status within that
Expand Down Expand Up @@ -597,6 +599,7 @@ func TestPullStatus_UpdateProject(t *testing.T) {
Status: models.AppliedPlanStatus,
},
}, status.Projects) // nolint: staticcheck
b.Close()
}

// Test that if we update an existing pull status and our new status is for a
Expand Down Expand Up @@ -659,6 +662,7 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) {
Status: models.AppliedPlanStatus,
},
}, maybeStatus.Projects)
b.Close()
}

// Test that if we update an existing pull status via Apply and our new status is for a
Expand Down Expand Up @@ -771,6 +775,7 @@ func TestPullStatus_UpdateMerge_Apply(t *testing.T) {
},
}, updateStatus.Projects)
}
b.Close()
}

// Test that if we update one existing policy status via approve_policies and our new status is for a
Expand Down Expand Up @@ -885,6 +890,7 @@ func TestPullStatus_UpdateMerge_ApprovePolicies(t *testing.T) {
},
}, updateStatus.Projects)
}
b.Close()
}

// newTestDB returns a TestDB using a temporary path.
Expand Down Expand Up @@ -925,6 +931,6 @@ func newTestDB2(t *testing.T) *db.BoltDB {
}

func cleanupDB(db *bolt.DB) {
os.Remove(db.Path()) // nolint: errcheck
db.Close() // nolint: errcheck
os.Remove(db.Path()) // nolint: errcheck
}
3 changes: 3 additions & 0 deletions server/events/apply_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func TestApplyCommandRunner_IsSilenced(t *testing.T) {
// create an empty DB
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)

vcsClient := setup(t, func(tc *TestConfig) {
Expand Down
42 changes: 42 additions & 0 deletions server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func setup(t *testing.T, options ...func(testConfig *TestConfig)) *vcsmocks.Mock
// create an empty DB
tmp := t.TempDir()
defaultBoltDB, err := db.New(tmp)
t.Cleanup(func() {
defaultBoltDB.Close()
})
Ok(t, err)

testConfig := &TestConfig{
Expand Down Expand Up @@ -786,6 +789,9 @@ func TestRunAutoplanCommand_DeletePlans(t *testing.T) {
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand Down Expand Up @@ -813,6 +819,9 @@ func TestRunAutoplanCommand_FailedPreWorkflowHook_FailOnPreWorkflowHookError_Fal
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand All @@ -837,6 +846,9 @@ func TestRunAutoplanCommand_FailedPreWorkflowHook_FailOnPreWorkflowHookError_Tru
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand All @@ -859,6 +871,9 @@ func TestRunCommentCommand_FailedPreWorkflowHook_FailOnPreWorkflowHookError_Fals
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand All @@ -881,6 +896,9 @@ func TestRunCommentCommand_FailedPreWorkflowHook_FailOnPreWorkflowHookError_True
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand All @@ -899,6 +917,9 @@ func TestRunGenericPlanCommand_DeletePlans(t *testing.T) {
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand All @@ -921,6 +942,9 @@ func TestRunSpecificPlanCommandDoesnt_DeletePlans(t *testing.T) {
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand All @@ -941,6 +965,9 @@ func TestRunAutoplanCommandWithError_DeletePlans(t *testing.T) {

tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand Down Expand Up @@ -993,6 +1020,9 @@ func TestRunGenericPlanCommand_DiscardApprovals(t *testing.T) {

tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand All @@ -1018,6 +1048,9 @@ func TestFailedApprovalCreatesFailedStatusUpdate(t *testing.T) {
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand Down Expand Up @@ -1064,6 +1097,9 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) {
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand Down Expand Up @@ -1120,6 +1156,9 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) {
setup(t)
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand Down Expand Up @@ -1198,6 +1237,9 @@ func TestRunApply_DiscardedProjects(t *testing.T) {
defer func() { autoMerger.GlobalAutomerge = false }()
tmp := t.TempDir()
boltDB, err := db.New(tmp)
t.Cleanup(func() {
boltDB.Close()
})
Ok(t, err)
dbUpdater.Backend = boltDB
applyCommandRunner.Backend = boltDB
Expand Down
3 changes: 3 additions & 0 deletions server/events/delete_lock_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func TestDeleteLock_Success(t *testing.T) {
}, nil)
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)
dlc := events.DefaultDeleteLockCommand{
Locker: l,
Expand Down
9 changes: 9 additions & 0 deletions server/events/plan_command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func TestPlanCommandRunner_IsSilenced(t *testing.T) {
// create an empty DB
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)

vcsClient := setup(t, func(tc *TestConfig) {
Expand Down Expand Up @@ -463,6 +466,9 @@ func TestPlanCommandRunner_ExecutionOrder(t *testing.T) {

tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)

vcsClient := setup(t, func(tc *TestConfig) {
Expand Down Expand Up @@ -700,6 +706,9 @@ func TestPlanCommandRunner_AtlantisApplyStatus(t *testing.T) {
// create an empty DB
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)

vcsClient := setup(t, func(tc *TestConfig) {
Expand Down
12 changes: 12 additions & 0 deletions server/events/pull_closed_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func TestCleanUpPullWorkspaceErr(t *testing.T) {
w := mocks.NewMockWorkingDir()
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)
pce := events.PullClosedExecutor{
WorkingDir: w,
Expand All @@ -63,6 +66,9 @@ func TestCleanUpPullUnlockErr(t *testing.T) {
l := lockmocks.NewMockLocker()
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)
pce := events.PullClosedExecutor{
Locker: l,
Expand All @@ -85,6 +91,9 @@ func TestCleanUpPullNoLocks(t *testing.T) {
cp := vcsmocks.NewMockClient()
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)
pce := events.PullClosedExecutor{
Locker: l,
Expand Down Expand Up @@ -182,6 +191,9 @@ func TestCleanUpPullComments(t *testing.T) {
l := lockmocks.NewMockLocker()
tmp := t.TempDir()
db, err := db.New(tmp)
t.Cleanup(func() {
db.Close()
})
Ok(t, err)
pce := events.PullClosedExecutor{
Locker: l,
Expand Down