Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(taskrun): roll back leaked test transactions (#21401)

Danny Xu5fdab92ddb4e
diff --git a/backend/runner/taskrun/running_scheduler_test.go b/backend/runner/taskrun/running_scheduler_test.go
index b62aa2c001..cfbfe75150 100644
--- a/backend/runner/taskrun/running_scheduler_test.go
+++ b/backend/runner/taskrun/running_scheduler_test.go
@@ -167,6 +167,7 @@ func TestValidateTaskFreshnessChecksInstanceArchival(t *testing.T) {
tx, err := s.GetDB().BeginTx(ctx, nil)
require.NoError(t, err)
+ defer tx.Rollback()
tasks, err := s.CreateMissingTasksTx(ctx, tx, plan.ProjectID, plan.UID, []*store.TaskMessage{{
InstanceID: instanceID,
Type: storepb.Task_DATABASE_CREATE,
@@ -214,6 +215,7 @@ func TestScheduleRunningTaskRunsSkipsArchivedInstance(t *testing.T) {
tx, err := s.GetDB().BeginTx(ctx, nil)
require.NoError(t, err)
+ defer tx.Rollback()
tasks, err := s.CreateMissingTasksTx(ctx, tx, plan.ProjectID, plan.UID, []*store.TaskMessage{{
InstanceID: instanceID,
Type: storepb.Task_DATABASE_CREATE,
diff --git a/backend/runner/taskrun/scheduler_test.go b/backend/runner/taskrun/scheduler_test.go
index 78cd9fbc74..bbc259ea1c 100644
--- a/backend/runner/taskrun/scheduler_test.go
+++ b/backend/runner/taskrun/scheduler_test.go
@@ -33,6 +33,10 @@ func TestTaskCyclesRecordEmptySuccess(t *testing.T) {
require.NoError(t, scheduler.scheduleRunningTaskRuns(ctx))
tx, err := stores.GetDB().BeginTx(ctx, nil)
require.NoError(t, err)
+ // The explicit Rollback below is what releases the advisory lock. This guards the
+ // path where a require between here and there calls t.FailNow: that skips the
+ // explicit Rollback and would strand the lock for the rest of the package.
+ defer tx.Rollback()
acquired, err := store.TryAdvisoryXactLock(ctx, tx, store.AdvisoryLockKeyPendingScheduler)
require.NoError(t, err)
require.True(t, acquired)
@@ -118,6 +122,7 @@ func TestSchedulePendingTaskRunsSkipsArchivedProject(t *testing.T) {
tx, err := s.GetDB().BeginTx(ctx, nil)
require.NoError(t, err)
+ defer tx.Rollback()
tasks, err := s.CreateMissingTasksTx(ctx, tx, plan.ProjectID, plan.UID, []*store.TaskMessage{{
InstanceID: "unused",
Type: storepb.Task_TASK_TYPE_UNSPECIFIED,
@@ -184,6 +189,7 @@ func TestSchedulePendingTaskRunsSkipsArchivedInstance(t *testing.T) {
tx, err := s.GetDB().BeginTx(ctx, nil)
require.NoError(t, err)
+ defer tx.Rollback()
tasks, err := s.CreateMissingTasksTx(ctx, tx, plan.ProjectID, plan.UID, []*store.TaskMessage{{
InstanceID: instanceID,
Type: storepb.Task_TASK_TYPE_UNSPECIFIED,