1
- import { describe , test , expect , beforeAll , beforeEach } from '@jest/globals' ;
1
+ import {
2
+ describe ,
3
+ test ,
4
+ expect ,
5
+ beforeAll ,
6
+ beforeEach ,
7
+ afterAll ,
8
+ } from '@jest/globals' ;
2
9
import RunClient from '../src/tracking/RunClient' ;
3
10
import ExperimentClient from '../src/tracking/ExperimentClient' ;
4
11
import {
@@ -13,6 +20,8 @@ describe('RunClient', () => {
13
20
let runClient : RunClient ;
14
21
let experimentClient : ExperimentClient ;
15
22
let experimentId : string ;
23
+ let run : Run ;
24
+ const testIds : string [ ] = [ ] ;
16
25
17
26
beforeAll ( async ( ) => {
18
27
await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
@@ -24,12 +33,22 @@ describe('RunClient', () => {
24
33
experimentId = await experimentClient . createExperiment (
25
34
`Testing ${ timestamp } `
26
35
) ;
36
+ testIds . push ( experimentId ) ;
37
+ } ) ;
38
+
39
+ beforeEach ( async ( ) => {
40
+ run = ( await runClient . createRun ( experimentId ) ) as Run ;
41
+ } ) ;
42
+
43
+ afterAll ( async ( ) => {
44
+ for ( const testId of testIds ) {
45
+ await experimentClient . deleteExperiment ( testId ) ;
46
+ }
27
47
} ) ;
28
48
29
49
// POST - Create a new run within an experiment
30
50
describe ( 'createRun' , ( ) => {
31
51
test ( '- Should create a run with experiment_id' , async ( ) => {
32
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
33
52
expect ( run . info . experiment_id ) . toBe ( experimentId ) ;
34
53
} ) ;
35
54
@@ -101,8 +120,6 @@ describe('RunClient', () => {
101
120
// DELETE - Mark a run for deletion
102
121
describe ( 'deleteRun' , ( ) => {
103
122
test ( '- Should delete a run with run_id' , async ( ) => {
104
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
105
-
106
123
await expect ( runClient . deleteRun ( run . info . run_id ) ) . resolves . not . toThrow ( ) ;
107
124
108
125
// check if the run's lifecycle_stage has changed to "deleted"
@@ -128,11 +145,6 @@ describe('RunClient', () => {
128
145
129
146
// POST - Restore a deleted run
130
147
describe ( 'restoreRun' , ( ) => {
131
- let run : Run ;
132
- beforeEach ( async ( ) => {
133
- run = ( await runClient . createRun ( experimentId ) ) as Run ;
134
- } ) ;
135
-
136
148
test ( '- Should restore a deleted run with run_id' , async ( ) => {
137
149
await runClient . deleteRun ( run . info . run_id ) ;
138
150
@@ -180,8 +192,6 @@ describe('RunClient', () => {
180
192
// GET - Get metadata, metrics, params, and tags for a run
181
193
describe ( 'getRun' , ( ) => {
182
194
test ( '- Should retrieve metadata for a run with run_id' , async ( ) => {
183
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
184
-
185
195
// create dummy data for created run
186
196
const metrics : Metrics [ ] = [
187
197
{ key : 'accuracy' , value : 0.83 , timestamp : 1694000700000 } ,
@@ -240,12 +250,6 @@ describe('RunClient', () => {
240
250
241
251
// POST - Update run metadata
242
252
describe ( 'updateRun' , ( ) => {
243
- let run : Run ;
244
-
245
- beforeEach ( async ( ) => {
246
- run = ( await runClient . createRun ( experimentId ) ) as Run ;
247
- } ) ;
248
-
249
253
// parameterized testing for input status
250
254
const allStatuses = [
251
255
'RUNNING' ,
@@ -330,14 +334,9 @@ describe('RunClient', () => {
330
334
331
335
// POST - Log a metric for a run
332
336
describe ( 'logMetric' , ( ) => {
333
- let run : Run ;
334
337
const key = 'accuracy' ;
335
338
const value = 0.9 ;
336
339
337
- beforeEach ( async ( ) => {
338
- run = ( await runClient . createRun ( experimentId ) ) as Run ;
339
- } ) ;
340
-
341
340
test ( '- Should log a metric with run_id, key, value, and timestamp' , async ( ) => {
342
341
const timestamp = Date . now ( ) ;
343
342
@@ -405,12 +404,6 @@ describe('RunClient', () => {
405
404
406
405
// POST - Log a batch of metrics, params, and tags for a run
407
406
describe ( 'logBatch' , ( ) => {
408
- let run : Run ;
409
-
410
- beforeEach ( async ( ) => {
411
- run = ( await runClient . createRun ( experimentId ) ) as Run ;
412
- } ) ;
413
-
414
407
test ( '- Should not throw error with just run_id' , async ( ) => {
415
408
await expect (
416
409
runClient . logBatch ( run . info . run_id )
@@ -698,7 +691,6 @@ describe('RunClient', () => {
698
691
] ;
699
692
700
693
test ( '- Should log inputs with run_id and datasets' , async ( ) => {
701
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
702
694
await runClient . logInputs ( run . info . run_id , datasets ) ;
703
695
704
696
// fetch run to confirm changes
@@ -709,8 +701,6 @@ describe('RunClient', () => {
709
701
} ) ;
710
702
711
703
test ( '- Should handle errors and edge cases' , async ( ) => {
712
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
713
-
714
704
// test with invalid_id
715
705
const invalid_id = 'invalid_id' ;
716
706
await expect ( runClient . logInputs ( invalid_id , datasets ) ) . rejects . toThrow ( ) ;
@@ -733,11 +723,10 @@ describe('RunClient', () => {
733
723
734
724
// POST - Set a tag on a run
735
725
describe ( 'setTag' , ( ) => {
736
- test ( '- Should set a tag on a run with run_id, key, and value' , async ( ) => {
737
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
738
- const key = 'accuracy' ;
739
- const value = '0.99' ;
726
+ const key = 'accuracy' ;
727
+ const value = '0.99' ;
740
728
729
+ test ( '- Should set a tag on a run with run_id, key, and value' , async ( ) => {
741
730
await runClient . setTag ( run . info . run_id , key , value ) ;
742
731
743
732
// fetch run to confirm changes
@@ -748,10 +737,6 @@ describe('RunClient', () => {
748
737
} ) ;
749
738
750
739
test ( '- Should handle errors and edge cases' , async ( ) => {
751
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
752
- const key = 'accuracy' ;
753
- const value = '0.99' ;
754
-
755
740
// test missing arguments
756
741
// @ts -expect-error: testing for all missing arguments
757
742
await expect ( runClient . setTag ( ) ) . rejects . toThrow ( ) ;
@@ -793,8 +778,6 @@ describe('RunClient', () => {
793
778
const key = 'test_key' ;
794
779
const value = 'test_value' ;
795
780
test ( '- Should delete a tag on a run with run_id and key' , async ( ) => {
796
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
797
-
798
781
await runClient . setTag ( run . info . run_id , key , value ) ;
799
782
800
783
await runClient . deleteTag ( run . info . run_id , key ) ;
@@ -808,8 +791,6 @@ describe('RunClient', () => {
808
791
} ) ;
809
792
810
793
test ( '- Should handle errors and edge cases' , async ( ) => {
811
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
812
-
813
794
// testing missing arguments
814
795
// @ts -expect-error: testing for all missing arguments
815
796
await expect ( runClient . deleteTag ( ) ) . rejects . toThrow ( ) ;
@@ -844,11 +825,10 @@ describe('RunClient', () => {
844
825
845
826
// POST - Log a param used for a run
846
827
describe ( 'logParam' , ( ) => {
847
- test ( '- Should log a param used for a run with run_id, key, and value' , async ( ) => {
848
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
828
+ const key = 'learning_rate' ;
829
+ const value = '0.001' ;
849
830
850
- const key = 'learning_rate' ;
851
- const value = '0.001' ;
831
+ test ( '- Should log a param used for a run with run_id, key, and value' , async ( ) => {
852
832
await runClient . logParam ( run . info . run_id , key , value ) ;
853
833
854
834
// fetch run to confirm changes
@@ -859,10 +839,6 @@ describe('RunClient', () => {
859
839
} ) ;
860
840
861
841
test ( '- Should handle errors and edge cases' , async ( ) => {
862
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
863
- const key = 'learning_rate' ;
864
- const value = '0.001' ;
865
-
866
842
// @ts -expect-error: testing for all missing arguments
867
843
await expect ( runClient . logParam ( ) ) . rejects . toThrow ( ) ;
868
844
// @ts -expect-error: testing for missing key and value
@@ -886,11 +862,10 @@ describe('RunClient', () => {
886
862
887
863
// Get a list of all valuse for the specified metric for a given run
888
864
describe ( 'getMetricHisotry' , ( ) => {
889
- test ( '- Should get a list of all values for the specified metric for a given run with run_id and metric_key' , async ( ) => {
890
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
891
- const key = 'accuracy' ;
892
- const value = 0.95 ;
865
+ const key = 'accuracy' ;
866
+ const value = 0.95 ;
893
867
868
+ test ( '- Should get a list of all values for the specified metric for a given run with run_id and metric_key' , async ( ) => {
894
869
await runClient . logMetric ( run . info . run_id , key , value ) ;
895
870
const metricHistory = ( await runClient . getMetricHistory (
896
871
run . info . run_id ,
@@ -1008,6 +983,7 @@ describe('RunClient', () => {
1008
983
const searchRunsExpId = await experimentClient . createExperiment (
1009
984
`Search Runs Test ${ Date . now ( ) } `
1010
985
) ;
986
+ testIds . push ( searchRunsExpId ) ;
1011
987
1012
988
const runA = ( await runClient . createRun ( searchRunsExpId ) ) as Run ;
1013
989
await runClient . logMetric ( runA . info . run_id , 'metric' , 1.0 ) ;
@@ -1067,7 +1043,6 @@ describe('RunClient', () => {
1067
1043
// List artifacts for a run
1068
1044
describe ( 'listArtifacts' , ( ) => {
1069
1045
test ( '- Should list artifacts with run_id' , async ( ) => {
1070
- const run = ( await runClient . createRun ( experimentId ) ) as Run ;
1071
1046
const artifacts = await runClient . listArtifacts ( run . info . run_id ) ;
1072
1047
1073
1048
expect ( artifacts ) . toHaveProperty ( 'root_uri' ) ;
0 commit comments