vitess.io/vitess@v0.16.2/web/vtadmin/src/components/charts/WorkflowStreamsLagChart.test.tsx (about) 1 /** 2 * Copyright 2021 The Vitess Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import { UseQueryResult } from 'react-query'; 18 import { TabletDebugVarsResponse } from '../../api/http'; 19 import { vtadmin as pb } from '../../proto/vtadmin'; 20 import { formatSeries } from './WorkflowStreamsLagChart'; 21 22 describe('WorkflowStreamsLagChart', () => { 23 describe('formatSeries', () => { 24 it('should return series for all streams in the workflow', () => { 25 const workflow = pb.Workflow.create({ 26 cluster: { 27 id: 'zone1', 28 name: 'zone1', 29 }, 30 workflow: { 31 shard_streams: { 32 '-80/us_east_1a-123456': { 33 streams: [ 34 { id: 1, shard: '-80', tablet: { cell: 'us_east_1a', uid: 123456 } }, 35 { id: 2, shard: '-80', tablet: { cell: 'us_east_1a', uid: 123456 } }, 36 ], 37 }, 38 '80-/us_east_1a-789012': { 39 streams: [{ id: 1, shard: '80-', tablet: { cell: 'us_east_1a', uid: 789012 } }], 40 }, 41 }, 42 }, 43 }); 44 45 const queries: Partial<UseQueryResult<TabletDebugVarsResponse, Error>>[] = [ 46 { 47 data: { 48 params: { alias: 'us_east_1a-123456', clusterID: 'zone1' }, 49 data: { 50 VReplicationLag: { 51 All: [3, 3, 3], 52 '1': [1, 1, 1], 53 '2': [2, 2, 2], 54 }, 55 }, 56 }, 57 dataUpdatedAt: 1000000000000, 58 }, 59 { 60 data: { 61 params: { alias: 'us_east_1a-789012', clusterID: 'zone1' }, 62 data: { 63 VReplicationLag: { 64 All: [], 65 '1': [1, 1, 1], 66 // Some other stream running on the tablet that isn't part 67 // of this workflow. 68 '2': [2, 2, 2], 69 }, 70 }, 71 }, 72 dataUpdatedAt: 1000000000000, 73 }, 74 ]; 75 76 // A sneaky cast to UseQueryResult since otherwise enumerating the many fields 77 // UseQueryResult (most of which we don't use) is pointlessly verbose. 78 const result = formatSeries(workflow, queries as UseQueryResult<TabletDebugVarsResponse, Error>[]); 79 80 // Use snapshot matching since defining expected values for arrays of 180 data points is... annoying. 81 expect(result).toMatchSnapshot(); 82 83 // ...but! Add additional validation so that failing tests are easier to debug. 84 // (And because it can be tempting to not examine snapshot changes in detail...) :) 85 expect(result.length).toEqual(3); 86 87 expect(result[0].name).toEqual('us_east_1a-123456/1'); 88 expect(result[1].name).toEqual('us_east_1a-123456/2'); 89 expect(result[2].name).toEqual('us_east_1a-789012/1'); 90 }); 91 92 it('should handle empty input', () => { 93 const result = formatSeries(null, []); 94 expect(result).toEqual([]); 95 }); 96 }); 97 });