@@ -89,8 +89,52 @@ describe('metrics effects', () => {
8989 selectors . getMetricsTooltipSort ,
9090 TooltipSort . ALPHABETICAL
9191 ) ;
92+
93+ overrideTagMetadata ( ) ;
94+ overrideRunToEid ( ) ;
9295 } ) ;
9396
97+ function overrideTagMetadata ( ) {
98+ store . overrideSelector ( selectors . getMetricsTagMetadata , {
99+ scalars : {
100+ tagDescriptions : { } as any ,
101+ tagToRuns : {
102+ tagA : [ 'run1' ] ,
103+ tagB : [ 'run2' , 'run3' ] ,
104+ tagC : [ 'run4' , 'run5' ] ,
105+ tagD : [ 'run6' ] ,
106+ } ,
107+ } ,
108+ histograms : {
109+ tagDescriptions : { } as any ,
110+ tagToRuns : {
111+ tagA : [ 'run1' ] ,
112+ tagB : [ 'run4' ] ,
113+ } ,
114+ } ,
115+ images : {
116+ tagDescriptions : { } ,
117+ tagRunSampledInfo : {
118+ tagC : {
119+ 'defaultExperimentId/run1' : { } as any ,
120+ 'exp1/run3' : { } as any ,
121+ } ,
122+ } ,
123+ } ,
124+ } ) ;
125+ }
126+
127+ function overrideRunToEid ( ) {
128+ store . overrideSelector ( selectors . getRunIdToExperimentId , {
129+ run1 : 'exp1' ,
130+ run2 : 'exp1' ,
131+ run3 : 'exp2' ,
132+ run4 : 'defaultExperimentId' ,
133+ run5 : 'defaultExperimentId' ,
134+ run6 : 'defaultExperimentId' ,
135+ } ) ;
136+ }
137+
94138 afterEach ( ( ) => {
95139 store ?. resetSelectors ( ) ;
96140 } ) ;
@@ -365,35 +409,25 @@ describe('metrics effects', () => {
365409 actions$ . next ( reloadAction ( ) ) ;
366410
367411 expect ( fetchTagMetadataSpy ) . toHaveBeenCalled ( ) ;
368- expect ( fetchTimeSeriesSpy ) . toHaveBeenCalledTimes ( 2 ) ;
412+ expect ( fetchTimeSeriesSpy ) . toHaveBeenCalledTimes ( 1 ) ;
369413 expect ( actualActions ) . toEqual ( [
370414 actions . metricsTagMetadataRequested ( ) ,
371415 actions . metricsTagMetadataLoaded ( {
372416 tagMetadata : buildDataSourceTagMetadata ( ) ,
373417 } ) ,
374418
375- // Currently we expect 2x the same requests if the cards are the same.
376- // Ideally we should dedupe requests for the same info.
377419 actions . multipleTimeSeriesRequested ( {
378420 requests : [
379421 {
380422 plugin : PluginType . SCALARS as MultiRunPluginType ,
381423 tag : 'tagA' ,
382424 experimentIds : [ 'exp1' ] ,
383425 } ,
384- {
385- plugin : PluginType . SCALARS as MultiRunPluginType ,
386- tag : 'tagA' ,
387- experimentIds : [ 'exp1' ] ,
388- } ,
389426 ] ,
390427 } ) ,
391428 actions . fetchTimeSeriesLoaded ( {
392429 response : buildTimeSeriesResponse ( ) ,
393430 } ) ,
394- actions . fetchTimeSeriesLoaded ( {
395- response : buildTimeSeriesResponse ( ) ,
396- } ) ,
397431 ] ) ;
398432 } ) ;
399433
@@ -487,6 +521,8 @@ describe('metrics effects', () => {
487521 it ( 'does not re-fetch time series, until a valid experiment id' , ( ) => {
488522 // Reset any `getExperimentIdsFromRoute` overrides above.
489523 store . resetSelectors ( ) ;
524+ overrideTagMetadata ( ) ;
525+ overrideRunToEid ( ) ;
490526 store . overrideSelector ( getActivePlugin , METRICS_PLUGIN_ID ) ;
491527 store . overrideSelector (
492528 selectors . getVisibleCardIdSet ,
@@ -510,6 +546,43 @@ describe('metrics effects', () => {
510546
511547 expect ( fetchTimeSeriesSpy ) . toHaveBeenCalledTimes ( 2 ) ;
512548 } ) ;
549+
550+ it ( 'does not send requests to experiments lacking a cards tag' , ( ) => {
551+ store . overrideSelector ( getActivePlugin , METRICS_PLUGIN_ID ) ;
552+ store . overrideSelector ( selectors . getExperimentIdsFromRoute , [
553+ 'exp1' ,
554+ 'exp2' ,
555+ ] ) ;
556+ store . overrideSelector (
557+ selectors . getVisibleCardIdSet ,
558+ new Set ( [ 'card1' , 'card2' ] )
559+ ) ;
560+ provideCardFetchInfo ( [
561+ { id : 'card1' , tag : 'tagA' } ,
562+ { id : 'card2' , tag : 'tagB' } ,
563+ ] ) ;
564+ store . refreshState ( ) ;
565+
566+ const effectFetchTimeSeriesSpy = spyOn (
567+ effects as any ,
568+ 'fetchTimeSeries'
569+ ) . and . stub ( ) ;
570+
571+ actions$ . next ( coreActions . manualReload ( ) ) ;
572+
573+ expect ( effectFetchTimeSeriesSpy ) . toHaveBeenCalledTimes ( 2 ) ;
574+ expect ( effectFetchTimeSeriesSpy ) . toHaveBeenCalledWith ( {
575+ plugin : 'scalars' ,
576+ tag : 'tagA' ,
577+ experimentIds : [ 'exp1' ] ,
578+ } ) ;
579+
580+ expect ( effectFetchTimeSeriesSpy ) . toHaveBeenCalledWith ( {
581+ plugin : 'scalars' ,
582+ tag : 'tagB' ,
583+ experimentIds : [ 'exp1' , 'exp2' ] ,
584+ } ) ;
585+ } ) ;
513586 } ) ;
514587
515588 describe ( 'loadTimeSeriesForVisibleCardsWithoutData' , ( ) => {
@@ -778,4 +851,24 @@ describe('metrics effects', () => {
778851 }
779852 } ) ;
780853 } ) ;
854+
855+ describe ( '#utilities' , ( ) => {
856+ describe ( 'parseRunIdFromSampledRunInfoName' , ( ) => {
857+ it ( 'removes prefixed experiment id' , ( ) => {
858+ expect (
859+ TEST_ONLY . parseRunIdFromSampledRunInfoName ( 'experimentId/someRun' )
860+ ) . toEqual ( 'someRun' ) ;
861+ } ) ;
862+
863+ it ( 'preserves "/" characters in run names' , ( ) => {
864+ expect (
865+ TEST_ONLY . parseRunIdFromSampledRunInfoName ( 'experimentId/some/run' )
866+ ) . toEqual ( 'some/run' ) ;
867+ } ) ;
868+
869+ it ( 'returns an empty string when an empty string is provided' , ( ) => {
870+ expect ( TEST_ONLY . parseRunIdFromSampledRunInfoName ( '' ) ) . toEqual ( '' ) ;
871+ } ) ;
872+ } ) ;
873+ } ) ;
781874} ) ;
0 commit comments