Skip to content

Commit d21de3f

Browse files
author
Anuar Talipov
committed
Add reducer and effects tests.
1 parent 4636557 commit d21de3f

File tree

6 files changed

+327
-29
lines changed

6 files changed

+327
-29
lines changed

tensorboard/webapp/runs/actions/runs_actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const fetchRunsSucceeded = createAction(
4040
experimentIds: string[];
4141
runsForAllExperiments: Run[];
4242
newRuns: ExperimentIdToRuns;
43+
expNameByExpId?: Record<string, string>; // Should we make this optional?
4344
}>()
4445
);
4546

tensorboard/webapp/runs/effects/runs_effects.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getExperimentIdsFromRoute,
3737
getRuns,
3838
getRunsLoadState,
39+
getDashboardExperimentNames
3940
} from '../../selectors';
4041
import {DataLoadState, LoadState} from '../../types/data';
4142
import * as actions from '../actions';
@@ -217,12 +218,20 @@ export class RunsEffects {
217218
}
218219
return {newRuns, runsForAllExperiments};
219220
}),
220-
tap(({newRuns, runsForAllExperiments}) => {
221+
withLatestFrom(
222+
this.store.select(getDashboardExperimentNames)
223+
),
224+
map(([runsData, expNameByExpId]) => {
225+
const {newRuns, runsForAllExperiments} = runsData;
226+
return {newRuns, runsForAllExperiments, expNameByExpId};
227+
}),
228+
tap(({newRuns, runsForAllExperiments, expNameByExpId}) => {
221229
this.store.dispatch(
222230
actions.fetchRunsSucceeded({
223231
experimentIds,
224232
newRuns,
225233
runsForAllExperiments,
234+
expNameByExpId
226235
})
227236
);
228237
}),

tensorboard/webapp/runs/effects/runs_effects_test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import * as coreActions from '../../core/actions';
2929
import * as hparamsActions from '../../hparams/_redux/hparams_actions';
3030
import {
3131
getActiveRoute,
32+
getDashboardExperimentNames,
3233
getExperimentIdsFromRoute,
3334
getRuns,
3435
getRunsLoadState,
@@ -131,6 +132,10 @@ describe('runs_effects', () => {
131132
buildCompareRoute(['exp1:123', 'exp2:456'])
132133
);
133134
store.overrideSelector(getExperimentIdsFromRoute, ['123', '456']);
135+
store.overrideSelector(getDashboardExperimentNames, {
136+
456: 'exp2',
137+
123: 'exp1'
138+
});
134139
const createFooRuns = () => [
135140
createRun({
136141
id: 'foo/runA',
@@ -166,6 +171,10 @@ describe('runs_effects', () => {
166171
runs: createFooRuns(),
167172
},
168173
},
174+
expNameByExpId: {
175+
456: 'exp2',
176+
123: 'exp1'
177+
}
169178
}),
170179
]);
171180
});
@@ -211,6 +220,10 @@ describe('runs_effects', () => {
211220
buildCompareRoute(['exp1:123', ' exp2:456'])
212221
);
213222
store.overrideSelector(getExperimentIdsFromRoute, ['123', '456']);
223+
store.overrideSelector(getDashboardExperimentNames, {
224+
456: 'exp2',
225+
123: 'exp1'
226+
});
214227
store.refreshState();
215228

216229
action.next(specAction());
@@ -244,6 +257,10 @@ describe('runs_effects', () => {
244257
runs: createBarRuns(),
245258
},
246259
},
260+
expNameByExpId: {
261+
456: 'exp2',
262+
123: 'exp1'
263+
}
247264
}),
248265
]);
249266
});
@@ -310,6 +327,10 @@ describe('runs_effects', () => {
310327
buildCompareRoute(['exp1:123', ' exp2:456'])
311328
);
312329
store.overrideSelector(getExperimentIdsFromRoute, ['123', '456']);
330+
store.overrideSelector(getDashboardExperimentNames, {
331+
456: 'exp1',
332+
123: 'exp2'
333+
});
313334
store.refreshState();
314335

315336
action.next(buildNavigatedAction());
@@ -328,13 +349,18 @@ describe('runs_effects', () => {
328349
runs: createBarRuns(),
329350
},
330351
},
352+
expNameByExpId: {
353+
456: 'exp1',
354+
123: 'exp2'
355+
}
331356
}),
332357
]);
333358
});
334359

335360
it('ignores a navigation to same route and experiments (hash changes)', () => {
336361
store.overrideSelector(getActiveRoute, buildRoute());
337362
store.overrideSelector(getExperimentIdsFromRoute, ['123']);
363+
store.overrideSelector(getDashboardExperimentNames, {123: 'exp1'});
338364
const createFooRuns = () => [
339365
createRun({
340366
id: 'foo/runA',
@@ -363,6 +389,7 @@ describe('runs_effects', () => {
363389
experimentIds: ['123'],
364390
runsForAllExperiments: [...createFooRuns()],
365391
newRuns: {},
392+
expNameByExpId: {123: 'exp1'}
366393
}),
367394
]);
368395

@@ -391,6 +418,7 @@ describe('runs_effects', () => {
391418
})
392419
);
393420
store.overrideSelector(getExperimentIdsFromRoute, ['foo']);
421+
store.overrideSelector(getDashboardExperimentNames, {foo: 'exp1'});
394422
store.refreshState();
395423

396424
action.next(buildNavigatedAction());
@@ -404,6 +432,7 @@ describe('runs_effects', () => {
404432
experimentIds: ['foo'],
405433
runsForAllExperiments: [...createFooRuns()],
406434
newRuns: {},
435+
expNameByExpId: {foo: 'exp1'}
407436
}),
408437
]);
409438
});
@@ -457,6 +486,7 @@ describe('runs_effects', () => {
457486
// Emulate navigation to a new experiment route.
458487
store.overrideSelector(getActiveRoute, buildExperimentRouteFromId('456'));
459488
store.overrideSelector(getExperimentIdsFromRoute, ['456']);
489+
store.overrideSelector(getDashboardExperimentNames, {456: 'exp1', 123: 'exp2'});
460490
// Force selectors to re-evaluate with a change in store.
461491
store.refreshState();
462492

@@ -480,13 +510,15 @@ describe('runs_effects', () => {
480510
newRuns: {
481511
456: {runs: createBarRuns()},
482512
},
513+
expNameByExpId: {456: 'exp1', 123: 'exp2'}
483514
}),
484515
actions.fetchRunsSucceeded({
485516
experimentIds: ['123'],
486517
runsForAllExperiments: createFooRuns(),
487518
newRuns: {
488519
123: {runs: createFooRuns()},
489520
},
521+
expNameByExpId: {456: 'exp1', 123: 'exp2'}
490522
}),
491523
]);
492524
});
@@ -552,6 +584,7 @@ describe('runs_effects', () => {
552584
});
553585

554586
store.overrideSelector(getExperimentIdsFromRoute, ['foo']);
587+
store.overrideSelector(getDashboardExperimentNames, {foo: 'exp1', bar: 'exp2'});
555588
selectSpy
556589
.withArgs(getRuns, {experimentId: 'foo'})
557590
.and.returnValue(runsSubject);
@@ -611,6 +644,7 @@ describe('runs_effects', () => {
611644
runs: createFooAfterRuns(),
612645
},
613646
},
647+
expNameByExpId: {foo: 'exp1', bar: 'exp2'}
614648
}),
615649
actions.fetchRunsSucceeded({
616650
experimentIds: ['foo', 'bar'],
@@ -623,6 +657,7 @@ describe('runs_effects', () => {
623657
runs: createBarRuns(),
624658
},
625659
},
660+
expNameByExpId: {foo: 'exp1', bar: 'exp2'}
626661
}),
627662
]);
628663
});

tensorboard/webapp/runs/store/runs_reducers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const dataReducer: ActionReducer<RunsDataState, Action> = createReducer(
204204
}
205205
return {...state, runsLoadState: nextRunsLoadState};
206206
}),
207-
on(runsActions.fetchRunsSucceeded, (state, {runsForAllExperiments}) => {
207+
on(runsActions.fetchRunsSucceeded, (state, {runsForAllExperiments, expNameByExpId}) => {
208208
const groupKeyToColorId = new Map(state.groupKeyToColorId);
209209
const defaultRunColorIdForGroupBy = new Map(
210210
state.defaultRunColorIdForGroupBy
@@ -220,7 +220,8 @@ const dataReducer: ActionReducer<RunsDataState, Action> = createReducer(
220220
const groups = groupRuns(
221221
groupBy,
222222
runsForAllExperiments,
223-
state.runIdToExpId
223+
state.runIdToExpId,
224+
expNameByExpId
224225
);
225226

226227
Object.entries(groups.matches).forEach(([groupId, runs]) => {

0 commit comments

Comments
 (0)