diff --git a/pkg/db/v1alpha2/interface.go b/pkg/db/v1alpha2/interface.go index 4a8054a3e0c..88b8261adc6 100644 --- a/pkg/db/v1alpha2/interface.go +++ b/pkg/db/v1alpha2/interface.go @@ -159,9 +159,27 @@ func (d *dbConn) RegisterExperiment(experiment *v1alpha2.Experiment) error { } else { return fmt.Errorf("Invalid experiment: spec is nil.") } + now_str := time.Now().UTC().Format(mysqlTimeFmt) start_time = now_str completion_time = now_str + if experiment.ExperimentStatus != nil { + if experiment.ExperimentStatus.StartTime != "" { + s_time, err := time.Parse(time.RFC3339Nano, experiment.ExperimentStatus.StartTime) + if err != nil { + return fmt.Errorf("Error parsing start time %s: %v", experiment.ExperimentStatus.StartTime, err) + } + start_time = s_time.UTC().Format(mysqlTimeFmt) + } + if experiment.ExperimentStatus.CompletionTime != "" { + c_time, err := time.Parse(time.RFC3339Nano, experiment.ExperimentStatus.CompletionTime) + if err != nil { + return fmt.Errorf("Error parsing completion time %s: %v", experiment.ExperimentStatus.CompletionTime, err) + } + completion_time = c_time.UTC().Format(mysqlTimeFmt) + } + } + _, err = d.db.Exec( `INSERT INTO experiments ( name, diff --git a/pkg/db/v1alpha2/interface_test.go b/pkg/db/v1alpha2/interface_test.go index decc6dfa812..4aadb02c3d2 100644 --- a/pkg/db/v1alpha2/interface_test.go +++ b/pkg/db/v1alpha2/interface_test.go @@ -107,7 +107,7 @@ func TestRegisterExperiment(t *testing.T) { ExperimentStatus: &api_pb.ExperimentStatus{ Condition: api_pb.ExperimentStatus_CREATED, StartTime: "2016-12-31T20:02:05.123456Z", - CompletionTime: "", + CompletionTime: "2016-12-31T20:02:06.123456Z", }, } mock.ExpectExec( @@ -135,7 +135,7 @@ func TestRegisterExperiment(t *testing.T) { experiment.ExperimentSpec.MaxTrialCount, experiment.ExperimentStatus.Condition, "2016-12-31 20:02:05.123456", - "", + "2016-12-31 20:02:06.123456", "", ).WillReturnResult(sqlmock.NewResult(1, 1)) err := dbInterface.RegisterExperiment(experiment) @@ -158,7 +158,7 @@ func TestGetExperiment(t *testing.T) { 100, api_pb.ExperimentStatus_CREATED, "2016-12-31 20:02:05.123456", - "", + "2016-12-31 20:02:06.123456", "", ), ) @@ -176,7 +176,7 @@ func TestGetExperimentList(t *testing.T) { "test1", api_pb.ExperimentStatus_CREATED, "2016-12-31 20:02:05.123456", - "", + "2016-12-31 20:02:06.123456", ).AddRow( "test2", api_pb.ExperimentStatus_SUCCEEDED, @@ -198,7 +198,7 @@ func TestUpdateExperimentStatus(t *testing.T) { condition := api_pb.ExperimentStatus_RUNNING exp_name := "test1" start_time := "2016-12-31 20:02:05.123456" - completion_time := "" + completion_time := "2016-12-31 20:02:06.123456" mock.ExpectExec(`UPDATE experiments SET status = \?, start_time = \?, @@ -209,7 +209,7 @@ func TestUpdateExperimentStatus(t *testing.T) { &api_pb.ExperimentStatus{ Condition: condition, StartTime: "2016-12-31T20:02:05.123456Z", - CompletionTime: "", + CompletionTime: "2016-12-31T20:02:06.123456Z", }, ) if err != nil { @@ -302,7 +302,7 @@ func TestRegisterTrial(t *testing.T) { }, }, StartTime: "2016-12-31T20:02:05.123456Z", - CompletionTime: "", + CompletionTime: "2016-12-31T20:02:06.123456Z", }, } mock.ExpectExec( @@ -327,7 +327,7 @@ func TestRegisterTrial(t *testing.T) { "{\"metrics\":[{\"name\":\"f1_score\",\"value\":\"88.95\"},{\"name\":\"loss\",\"value\":\"0.5\"},{\"name\":\"precision\",\"value\":\"88.7\"},{\"name\":\"recall\",\"value\":\"89.2\"}]}", trial.Status.Condition, "2016-12-31 20:02:05.123456", - "", + "2016-12-31 20:02:06.123456", ).WillReturnResult(sqlmock.NewResult(1, 1)) err := dbInterface.RegisterTrial(trial) if err != nil { @@ -349,7 +349,7 @@ func TestGetTrialList(t *testing.T) { "{\"metrics\":[{\"name\":\"f1_score\",\"value\":\"88.95\"},{\"name\":\"loss\",\"value\":\"0.5\"},{\"name\":\"precision\",\"value\":\"88.7\"},{\"name\":\"recall\",\"value\":\"89.2\"}]}", api_pb.TrialStatus_RUNNING, "2016-12-31 20:02:05.123456", - "", + "2016-12-31 20:02:06.123456", ).AddRow( 2, "test1_trial2", @@ -361,7 +361,7 @@ func TestGetTrialList(t *testing.T) { "{\"metrics\":[{\"name\":\"f1_score\",\"value\":\"88.5\"},{\"name\":\"loss\",\"value\":\"0.8\"},{\"name\":\"precision\",\"value\":\"88.2\"},{\"name\":\"recall\",\"value\":\"89.0\"}]}", api_pb.TrialStatus_COMPLETED, "2016-12-31 20:02:05.123456", - "", + "2016-12-31 20:02:06.123456", ), ) trials, err := dbInterface.GetTrialList("test1", "trial") @@ -387,7 +387,7 @@ func TestGetTrial(t *testing.T) { "{\"metrics\":[{\"name\":\"f1_score\",\"value\":\"88.95\"},{\"name\":\"loss\",\"value\":\"0.5\"},{\"name\":\"precision\",\"value\":\"88.7\"},{\"name\":\"recall\",\"value\":\"89.2\"}]}", api_pb.TrialStatus_RUNNING, "2016-12-31 20:02:05.123456", - "", + "2016-12-31 20:02:06.123456", ), ) trial, err := dbInterface.GetTrial("test1_trial1") @@ -402,7 +402,7 @@ func TestUpdateTrialStatus(t *testing.T) { condition := api_pb.TrialStatus_RUNNING trial_name := "test1_trial1" start_time := "2016-12-31 20:02:05.123456" - completion_time := "" + completion_time := "2016-12-31 20:02:06.123456" mock.ExpectExec(`UPDATE trials SET status = \?, start_time = \?, @@ -420,7 +420,7 @@ func TestUpdateTrialStatus(t *testing.T) { &api_pb.TrialStatus{ Condition: condition, StartTime: "2016-12-31T20:02:05.123456Z", - CompletionTime: "", + CompletionTime: "2016-12-31T20:02:06.123456Z", Observation: &api_pb.Observation{ Metrics: []*api_pb.Metric{ &api_pb.Metric{ diff --git a/test/scripts/v1alpha2/unit-test.sh b/test/scripts/v1alpha2/unit-test.sh index 98456626646..c2ed1d5f31e 100755 --- a/test/scripts/v1alpha2/unit-test.sh +++ b/test/scripts/v1alpha2/unit-test.sh @@ -17,60 +17,11 @@ # This shell script is used to build a cluster and create a namespace from our # argo workflow -exit 0 - set -o errexit set -o nounset set -o pipefail -export PATH=${GOPATH}/bin:/usr/local/go/bin:${PATH} -REGISTRY="${GCP_REGISTRY}" -CLUSTER_NAME="${CLUSTER_NAME}" -ZONE="${GCP_ZONE}" -PROJECT="${GCP_PROJECT}" GO_DIR=${GOPATH}/src/github.com/${REPO_OWNER}/${REPO_NAME} -VERSION=$(git describe --tags --always --dirty) - -echo "Activating service-account" -gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS} - -echo "Configuring kubectl" - -gcloud --project ${PROJECT} container clusters get-credentials ${CLUSTER_NAME} \ - --zone ${ZONE} -kubectl config set-context $(kubectl config current-context) --namespace=default - -kubectl apply -f - <