1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { 17 chartFuncDataSql, 18 chartFuncDataSqlMem, funcDataReceiver 19} from '../../../../../src/trace/database/data-trafic/process/FuncDataReceiver'; 20 21describe('FuncDataReceiver Test', () => { 22 let data; 23 let proc; 24 25 beforeEach(() => { 26 data = { 27 id: '55febc1a-1eea-4c9f-ad29-33cd10b95b39', 28 name: 31, 29 action: 'exec-proto', 30 params: { 31 tid: 8182, 32 ipid: 52, 33 startNS: 0, 34 endNS: 9427688540, 35 recordStartNS: 4049847357191, 36 recordEndNS: 4059275045731, 37 width: 549, 38 trafic: 0 39 } 40 }; 41 proc = jest.fn((sql: any) => [ 42 { 43 FuncData: { 44 startTs: 129966146, 45 dur: 0, 46 argsetid: 2128, 47 depth: 0, 48 id: 1090, 49 px: 7, 50 durTmp: 0 51 } 52 }, 53 { 54 FuncData: { 55 startTs: 155282292, 56 dur: 0, 57 argsetid: 3260, 58 depth: 0, 59 id: 1778, 60 px: 9, 61 durTmp: 0 62 } 63 }, 64 ]); 65 }); 66 it('FuncDataReceiverTest01 ', function () { 67 const args = { 68 recordStartNS: 1000, 69 endNS: 3000, 70 startNS: 2000, 71 width: 10 72 }; 73 expect(chartFuncDataSql(args)).toBeTruthy(); 74 expect(chartFuncDataSqlMem(args)).toBeTruthy(); 75 }); 76 it('FuncDataReceiverTest02 ', function () { 77 const mockPostMessage = jest.fn(); 78 global.postMessage = mockPostMessage; 79 funcDataReceiver(data, proc); 80 expect(mockPostMessage).toHaveBeenCalledTimes(1); 81 }); 82});