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

Fix ut test and enable ut-test of v1alpha2 #524

Merged
merged 1 commit into from
May 15, 2019
Merged
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
18 changes: 18 additions & 0 deletions pkg/db/v1alpha2/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions pkg/db/v1alpha2/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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",
"",
),
)
Expand All @@ -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,
Expand All @@ -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 = \?,
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand All @@ -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",
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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 = \?,
Expand All @@ -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{
Expand Down
49 changes: 0 additions & 49 deletions test/scripts/v1alpha2/unit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 - <<EOF
apiVersion: v1
kind: Pod
metadata:
labels:
instance: mysql-ut
name: mysql-ut
spec:
containers:
- name: mysql
image: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: test123
- name: MYSQL_DATABASE
value: vizier
EOF

TIMEOUT=120
until kubectl logs -l instance=mysql-ut |grep 'init process done'; do
sleep 10
TIMEOUT=$(( TIMEOUT - 1 ))
if [ "$TIMEOUT" -eq 0 ]; then
echo "DB failed to start"
kubectl get pod -l instance=mysql-ut
exit 1
fi
done

kubectl port-forward $(kubectl get pod -l instance=mysql-ut -o=name) 3306:3306&
export TEST_MYSQL=localhost

echo "Copy source to GOPATH"
mkdir -p ${GO_DIR}
Expand Down