@@ -2,6 +2,12 @@ import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
2
2
import { ApiError } from '../src/utils/apiError' ;
3
3
import ExperimentClient from '../src/tracking/ExperimentClient' ;
4
4
import ExperimentManager from '../src/workflows/ExperimentManager' ;
5
+ import {
6
+ createTestExperiment ,
7
+ deleteTestExperiments ,
8
+ runProperties ,
9
+ TRACKING_SERVER_URI ,
10
+ } from './testUtils' ;
5
11
6
12
describe ( 'ExperimentManager' , ( ) => {
7
13
let experimentClient : ExperimentClient ;
@@ -45,17 +51,14 @@ describe('ExperimentManager', () => {
45
51
beforeAll ( async ( ) => {
46
52
// Add a small delay to ensure MLflow is fully ready
47
53
await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
48
- experimentClient = new ExperimentClient ( 'http://127.0.0.1:5002' ) ;
49
- experimentManager = new ExperimentManager ( 'http://127.0.0.1:5002' ) ;
54
+ experimentClient = new ExperimentClient ( TRACKING_SERVER_URI ) ;
55
+ experimentManager = new ExperimentManager ( TRACKING_SERVER_URI ) ;
50
56
} ) ;
51
57
52
58
describe ( 'runExistingExperiment' , ( ) => {
53
59
test ( 'should run an existing experiment and return the run object' , async ( ) => {
54
- const num = Math . random ( ) . toString ( ) . slice ( 2 , 11 ) ;
55
- const name = `Test experiment ${ num } ` ;
56
- const exp = await experimentClient . createExperiment ( name ) ;
60
+ const exp : string = await createTestExperiment ( ) ;
57
61
testIds . push ( exp ) ;
58
-
59
62
const run = await experimentManager . runExistingExperiment (
60
63
exp ,
61
64
undefined ,
@@ -64,24 +67,14 @@ describe('ExperimentManager', () => {
64
67
tags ,
65
68
model
66
69
) ;
67
-
68
- expect ( run ) . toHaveProperty ( 'run_id' ) ;
69
- expect ( run ) . toHaveProperty ( 'run_uuid' ) ;
70
- expect ( run ) . toHaveProperty ( 'run_name' ) ;
71
- expect ( run ) . toHaveProperty ( 'experiment_id' ) ;
72
- expect ( run ) . toHaveProperty ( 'user_id' ) ;
73
- expect ( run ) . toHaveProperty ( 'status' ) ;
74
- expect ( run ) . toHaveProperty ( 'start_time' ) ;
75
- expect ( run ) . toHaveProperty ( 'artifact_uri' ) ;
76
- expect ( run ) . toHaveProperty ( 'lifecycle_stage' ) ;
70
+ for ( const property of runProperties ) {
71
+ expect ( run ) . toHaveProperty ( property ) ;
72
+ }
77
73
} ) ;
78
74
79
75
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 ) ;
76
+ const exp : string = await createTestExperiment ( ) ;
83
77
testIds . push ( exp ) ;
84
-
85
78
await expect (
86
79
experimentManager . runExistingExperiment (
87
80
'invalidExperimentId' ,
@@ -97,8 +90,7 @@ describe('ExperimentManager', () => {
97
90
98
91
describe ( 'runNewExperiment' , ( ) => {
99
92
test ( 'should run a new experiment and return the run object' , async ( ) => {
100
- const num = Math . random ( ) . toString ( ) . slice ( 2 , 11 ) ;
101
- const name = `Test experiment ${ num } ` ;
93
+ const name : string = `Test experiment ${ Date . now ( ) } ` ;
102
94
const run : {
103
95
experiment_id ?: string ;
104
96
} = await experimentManager . runNewExperiment (
@@ -112,22 +104,14 @@ describe('ExperimentManager', () => {
112
104
if ( run . experiment_id ) {
113
105
testIds . push ( run . experiment_id ) ;
114
106
}
115
-
116
- expect ( run ) . toHaveProperty ( 'run_id' ) ;
117
- expect ( run ) . toHaveProperty ( 'run_uuid' ) ;
118
- expect ( run ) . toHaveProperty ( 'run_name' ) ;
119
- expect ( run ) . toHaveProperty ( 'experiment_id' ) ;
120
- expect ( run ) . toHaveProperty ( 'user_id' ) ;
121
- expect ( run ) . toHaveProperty ( 'status' ) ;
122
- expect ( run ) . toHaveProperty ( 'start_time' ) ;
123
- expect ( run ) . toHaveProperty ( 'artifact_uri' ) ;
124
- expect ( run ) . toHaveProperty ( 'lifecycle_stage' ) ;
107
+ for ( const property of runProperties ) {
108
+ expect ( run ) . toHaveProperty ( property ) ;
109
+ }
125
110
} ) ;
126
111
127
112
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 ) ;
113
+ const name : string = `Test experiment ${ Date . now ( ) } ` ;
114
+ const exp : string = await experimentClient . createExperiment ( name ) ;
131
115
testIds . push ( exp ) ;
132
116
await expect (
133
117
experimentManager . runNewExperiment (
@@ -144,9 +128,7 @@ describe('ExperimentManager', () => {
144
128
145
129
describe ( 'experimentSummary' , ( ) => {
146
130
test ( "should return an array of all the passed-in experiment's runs, sorted according to the passed-in metric" , async ( ) => {
147
- const num = Math . random ( ) . toString ( ) . slice ( 2 , 11 ) ;
148
- const name = `Test experiment ${ num } ` ;
149
- const exp = await experimentClient . createExperiment ( name ) ;
131
+ const exp : string = await createTestExperiment ( ) ;
150
132
testIds . push ( exp ) ;
151
133
for ( const metric of metricsAll ) {
152
134
await experimentManager . runExistingExperiment (
@@ -176,12 +158,5 @@ describe('ExperimentManager', () => {
176
158
} ) ;
177
159
} ) ;
178
160
179
- afterAll ( async ( ) => {
180
- while ( testIds . length > 0 ) {
181
- const id = testIds . pop ( ) ;
182
- if ( id ) {
183
- await experimentClient . deleteExperiment ( id ) ;
184
- }
185
- }
186
- } ) ;
161
+ afterAll ( async ( ) => await deleteTestExperiments ( testIds ) ) ;
187
162
} ) ;
0 commit comments