Skip to content

Commit 081a19f

Browse files
committed
improving test coverage on ExpMgr.test.ts
1 parent a75f6ff commit 081a19f

File tree

1 file changed

+47
-25
lines changed

1 file changed

+47
-25
lines changed

mlflow/tests/ExperimentManager.test.ts

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
2+
import { ApiError } from '../src/utils/apiError';
23
import ExperimentClient from '../src/tracking/ExperimentClient';
34
import ExperimentManager from '../src/workflows/ExperimentManager';
45

@@ -34,22 +35,11 @@ describe('ExperimentManager', () => {
3435
mlflow_version: 'STRING',
3536
};
3637
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() }],
5343
];
5444

5545
beforeAll(async () => {
@@ -85,14 +75,32 @@ describe('ExperimentManager', () => {
8575
expect(run).toHaveProperty('artifact_uri');
8676
expect(run).toHaveProperty('lifecycle_stage');
8777
});
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+
});
8896
});
8997

9098
describe('runNewExperiment', () => {
9199
test('should run a new experiment and return the run object', async () => {
92100
const num = Math.random().toString().slice(2, 11);
93101
const name = `Test experiment ${num}`;
94-
const run: {
95-
experiment_id?: string
102+
const run: {
103+
experiment_id?: string;
96104
} = await experimentManager.runNewExperiment(
97105
name,
98106
undefined,
@@ -115,10 +123,27 @@ describe('ExperimentManager', () => {
115123
expect(run).toHaveProperty('artifact_uri');
116124
expect(run).toHaveProperty('lifecycle_stage');
117125
});
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+
});
118143
});
119144

120145
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 () => {
122147
const num = Math.random().toString().slice(2, 11);
123148
const name = `Test experiment ${num}`;
124149
const exp = await experimentClient.createExperiment(name);
@@ -132,17 +157,14 @@ describe('ExperimentManager', () => {
132157
tags,
133158
model
134159
);
135-
};
160+
}
136161

137162
type ExperimentSummaryResult = {
138163
metric1?: number;
139164
};
140165

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');
146168

147169
expect(Array.isArray(summary)).toBe(true);
148170
expect(summary.length).toBe(5);

0 commit comments

Comments
 (0)