1
1
import { describe , test , expect , beforeAll , afterAll } from '@jest/globals' ;
2
+ import { ApiError } from '../src/utils/apiError' ;
2
3
import ExperimentClient from '../src/tracking/ExperimentClient' ;
3
4
import ExperimentManager from '../src/workflows/ExperimentManager' ;
4
5
@@ -34,22 +35,11 @@ describe('ExperimentManager', () => {
34
35
mlflow_version : 'STRING' ,
35
36
} ;
36
37
const metricsAll = [
37
- [
38
- { key : 'metric1' , value : 0.1 , timestamp : Date . now ( ) }
39
- ] ,
40
- [
41
- { key : 'metric1' , value : 0.2 , timestamp : Date . now ( ) }
42
- ] ,
43
- [
44
- { key : 'metric1' , value : 0.3 , timestamp : Date . now ( ) }
45
- ] ,
46
- [
47
- { key : 'metric1' , value : 0.4 , timestamp : Date . now ( ) }
48
- ] ,
49
- [
50
- { key : 'metric1' , value : 0.5 , timestamp : Date . now ( ) }
51
- ] ,
52
-
38
+ [ { key : 'metric1' , value : 0.1 , timestamp : Date . now ( ) } ] ,
39
+ [ { key : 'metric1' , value : 0.2 , timestamp : Date . now ( ) } ] ,
40
+ [ { key : 'metric1' , value : 0.3 , timestamp : Date . now ( ) } ] ,
41
+ [ { key : 'metric1' , value : 0.4 , timestamp : Date . now ( ) } ] ,
42
+ [ { key : 'metric1' , value : 0.5 , timestamp : Date . now ( ) } ] ,
53
43
] ;
54
44
55
45
beforeAll ( async ( ) => {
@@ -85,14 +75,32 @@ describe('ExperimentManager', () => {
85
75
expect ( run ) . toHaveProperty ( 'artifact_uri' ) ;
86
76
expect ( run ) . toHaveProperty ( 'lifecycle_stage' ) ;
87
77
} ) ;
78
+
79
+ test ( 'should throw error if an invalid experiment ID is passed in' , async ( ) => {
80
+ const num = Math . random ( ) . toString ( ) . slice ( 2 , 11 ) ;
81
+ const name = `Test experiment ${ num } ` ;
82
+ const exp = await experimentClient . createExperiment ( name ) ;
83
+ testIds . push ( exp ) ;
84
+
85
+ await expect (
86
+ experimentManager . runExistingExperiment (
87
+ 'invalidExperimentId' ,
88
+ undefined ,
89
+ metrics ,
90
+ params ,
91
+ tags ,
92
+ model
93
+ )
94
+ ) . rejects . toThrow ( ApiError ) ;
95
+ } ) ;
88
96
} ) ;
89
97
90
98
describe ( 'runNewExperiment' , ( ) => {
91
99
test ( 'should run a new experiment and return the run object' , async ( ) => {
92
100
const num = Math . random ( ) . toString ( ) . slice ( 2 , 11 ) ;
93
101
const name = `Test experiment ${ num } ` ;
94
- const run : {
95
- experiment_id ?: string
102
+ const run : {
103
+ experiment_id ?: string ;
96
104
} = await experimentManager . runNewExperiment (
97
105
name ,
98
106
undefined ,
@@ -115,10 +123,27 @@ describe('ExperimentManager', () => {
115
123
expect ( run ) . toHaveProperty ( 'artifact_uri' ) ;
116
124
expect ( run ) . toHaveProperty ( 'lifecycle_stage' ) ;
117
125
} ) ;
126
+
127
+ test ( 'should throw error if an invalid experiment name is passed in' , async ( ) => {
128
+ const num = Math . random ( ) . toString ( ) . slice ( 2 , 11 ) ;
129
+ const name = `Test experiment ${ num } ` ;
130
+ const exp = await experimentClient . createExperiment ( name ) ;
131
+ testIds . push ( exp ) ;
132
+ await expect (
133
+ experimentManager . runNewExperiment (
134
+ name ,
135
+ undefined ,
136
+ metrics ,
137
+ params ,
138
+ tags ,
139
+ model
140
+ )
141
+ ) . rejects . toThrow ( ApiError ) ;
142
+ } ) ;
118
143
} ) ;
119
144
120
145
describe ( 'experimentSummary' , ( ) => {
121
- test ( ' should return an array of all the passed-in experiment\ 's runs, sorted according to the passed-in metric' , async ( ) => {
146
+ test ( " should return an array of all the passed-in experiment's runs, sorted according to the passed-in metric" , async ( ) => {
122
147
const num = Math . random ( ) . toString ( ) . slice ( 2 , 11 ) ;
123
148
const name = `Test experiment ${ num } ` ;
124
149
const exp = await experimentClient . createExperiment ( name ) ;
@@ -132,17 +157,14 @@ describe('ExperimentManager', () => {
132
157
tags ,
133
158
model
134
159
) ;
135
- } ;
160
+ }
136
161
137
162
type ExperimentSummaryResult = {
138
163
metric1 ?: number ;
139
164
} ;
140
165
141
- const summary : ExperimentSummaryResult [ ] = await experimentManager . experimentSummary (
142
- exp ,
143
- 'metric1' ,
144
- 'DESC'
145
- ) ;
166
+ const summary : ExperimentSummaryResult [ ] =
167
+ await experimentManager . experimentSummary ( exp , 'metric1' , 'DESC' ) ;
146
168
147
169
expect ( Array . isArray ( summary ) ) . toBe ( true ) ;
148
170
expect ( summary . length ) . toBe ( 5 ) ;
0 commit comments