diff --git a/master/internal/db/postgres_experiments.go b/master/internal/db/postgres_experiments.go index cc49349d4ee..3d7ca67da96 100644 --- a/master/internal/db/postgres_experiments.go +++ b/master/internal/db/postgres_experiments.go @@ -800,7 +800,7 @@ func (db *PgDB) TerminateExperimentInRestart(id int, state model.State) error { // Terminate trials. if _, err = tx.Exec( - `UPDATE trials SET state=$1, end_time=$2 WHERE experiment_id=$3 and end_time IS NULL`, + `UPDATE runs SET state=$1, end_time=$2 WHERE experiment_id=$3 and end_time IS NULL`, state, now, id, diff --git a/master/internal/db/postgres_experiments_intg_test.go b/master/internal/db/postgres_experiments_intg_test.go index 5e0eb3ae12a..fbee4f4a386 100644 --- a/master/internal/db/postgres_experiments_intg_test.go +++ b/master/internal/db/postgres_experiments_intg_test.go @@ -452,6 +452,34 @@ func TestExperimentByIDs(t *testing.T) { } } +func TestTerminateExperimentInRestart(t *testing.T) { + ctx := context.Background() + + require.NoError(t, etc.SetRootPath(RootFromDB)) + db := MustResolveTestPostgres(t) + MustMigrateTestPostgres(t, db, MigrationsFromDB) + user := RequireMockUser(t, db) + + exp := RequireMockExperiment(t, db, user) + trial0, _ := RequireMockTrial(t, db, exp) + trial1, _ := RequireMockTrial(t, db, exp) + + require.NoError(t, db.TerminateExperimentInRestart(exp.ID, model.ErrorState)) + + actualExp, err := ExperimentByID(ctx, exp.ID) + require.NoError(t, err) + require.Equal(t, actualExp.State, model.ErrorState) + require.NotNil(t, actualExp.EndTime) + require.Nil(t, actualExp.Progress) + + for _, trialID := range []int{trial0.ID, trial1.ID} { + actualTrial, err := TrialByID(ctx, trialID) + require.NoError(t, err) + require.Equal(t, actualTrial.State, model.ErrorState) + require.NotNil(t, actualTrial.EndTime) + } +} + func TestExperimentsTrialAndTaskIDs(t *testing.T) { ctx := context.Background()