-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YujiOshima <yuji.oshima0x3fd@gmail.com>
- Loading branch information
1 parent
cfbfbc1
commit 02d3d17
Showing
37 changed files
with
228,250 additions
and
257 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/golang/mock/gomock" | ||
api "github.com/kubeflow/hp-tuning/api" | ||
//"github.com/kubeflow/hp-tuning/mock/mock_api" | ||
"github.com/kubeflow/hp-tuning/mock/mock_db" | ||
"github.com/kubeflow/hp-tuning/mock/mock_worker_interface" | ||
"testing" | ||
) | ||
|
||
func TestCreateStudy(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
mockDB := mock_db.NewMockVizierDBInterface(ctrl) | ||
mockWif := mock_worker_interface.NewMockWorkerInterface(ctrl) | ||
sid := "teststudy" | ||
sc := &api.StudyConfig{ | ||
Name: "test", | ||
Owner: "admin", | ||
OptimizationType: 1, | ||
ObjectiveValueName: "obj_name", | ||
Gpu: 1, | ||
} | ||
dbIf = mockDB | ||
mockDB.EXPECT().CreateStudy( | ||
sc, | ||
).Return(sid, nil) | ||
s := &server{wIF: mockWif, StudyChList: make(map[string]studyCh)} | ||
req := &api.CreateStudyRequest{StudyConfig: sc} | ||
ret, err := s.CreateStudy(context.Background(), req) | ||
if err != nil { | ||
t.Fatalf("CreateStudy Error %v", err) | ||
} | ||
if ret.StudyId != sid { | ||
t.Fatalf("Study ID expect "+sid+", get %s", ret.StudyId) | ||
} | ||
if len(s.StudyChList) != 1 { | ||
t.Fatalf("Study register failed. Registered number is %d", len(s.StudyChList)) | ||
} else { | ||
_, ok := s.StudyChList[sid] | ||
if !ok { | ||
t.Fatalf("Study %s is failed to register.", sid) | ||
} | ||
} | ||
} | ||
func TestGetStudies(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
mockDB := mock_db.NewMockVizierDBInterface(ctrl) | ||
mockWif := mock_worker_interface.NewMockWorkerInterface(ctrl) | ||
sid := []string{"teststudy1", "teststudy2"} | ||
s := &server{wIF: mockWif, StudyChList: map[string]studyCh{sid[0]: studyCh{}, sid[1]: studyCh{}}} | ||
dbIf = mockDB | ||
|
||
sc := []*api.StudyConfig{ | ||
&api.StudyConfig{ | ||
Name: "test1", | ||
Owner: "admin", | ||
OptimizationType: 1, | ||
ObjectiveValueName: "obj_name1", | ||
Gpu: 1, | ||
}, | ||
&api.StudyConfig{ | ||
Name: "test2", | ||
Owner: "admin", | ||
OptimizationType: 1, | ||
ObjectiveValueName: "obj_name2", | ||
}, | ||
} | ||
rts := []int32{10, 20} | ||
cts := []int32{5, 1} | ||
for i := range sid { | ||
mockDB.EXPECT().GetStudyConfig(sid[i]).Return(sc[i], nil) | ||
mockWif.EXPECT().GetRunningTrials(sid[i]).Return(make([]*api.Trial, rts[i])) | ||
mockWif.EXPECT().GetCompletedTrials(sid[i]).Return(make([]*api.Trial, cts[i])) | ||
} | ||
|
||
req := &api.GetStudiesRequest{} | ||
ret, err := s.GetStudies(context.Background(), req) | ||
if err != nil { | ||
t.Fatalf("CreateStudy Error %v", err) | ||
} | ||
if len(ret.StudyInfos) != len(sid) { | ||
t.Fatalf("Study Info number %d, expected%d", len(ret.StudyInfos), len(sid)) | ||
} else { | ||
var j int | ||
for i := range sid { | ||
switch ret.StudyInfos[i].StudyId { | ||
case sid[0]: | ||
j = 0 | ||
case sid[1]: | ||
j = 1 | ||
default: | ||
t.Fatalf("GetStudy Error Study ID %s is not expected", ret.StudyInfos[j].StudyId) | ||
} | ||
if ret.StudyInfos[i].Name != sc[j].Name { | ||
t.Fatalf("GetStudy Error Name %s expected %s", ret.StudyInfos[i].Name, sc[j].Name) | ||
} | ||
if ret.StudyInfos[i].Owner != sc[j].Owner { | ||
t.Fatalf("GetStudy Error Owner %s expected %s", ret.StudyInfos[i].Owner, sc[j].Owner) | ||
} | ||
if ret.StudyInfos[i].RunningTrialNum != rts[j] { | ||
t.Fatalf("GetStudy Error RunningTrialNum %d expected %d", ret.StudyInfos[i].RunningTrialNum, rts[j]) | ||
} | ||
if ret.StudyInfos[i].CompletedTrialNum != cts[j] { | ||
t.Fatalf("GetStudy Error CompletedTrialNum %d expected %d", ret.StudyInfos[i].CompletedTrialNum, cts[j]) | ||
} | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.