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 16 17import { 18 chartHiperfCallChartDataSql, 19 hiPerfCallChartDataHandler, hiPerfCallStackCacheHandler 20} from '../../../../../src/trace/database/data-trafic/hiperf/HiperfCallChartReceiver'; 21 22describe('HiperfCallChartReceiver Test', () => { 23 let data; 24 let proc; 25 let data2; 26 beforeEach(() => { 27 data = { 28 id: "817fccf0-76a8-41f3-86d6-6282b1208b58", 29 name: 203, 30 action: "exec-proto", 31 params: { 32 recordStartNS: 1395573006744, 33 trafic: 2, 34 isCache: true 35 } 36 }; 37 data2 = { 38 id: "817fccf0-76a8-41f3-86d6-6282b1208b58", 39 name: 203, 40 action: "exec-proto", 41 params: { 42 recordStartNS: 1395573006744, 43 trafic: 2, 44 isCache: false 45 } 46 }; 47 proc = jest.fn((sql) => [ 48 {HiperfCallChartData: {callchainId: 4, startTs: 4.4, eventCount: 40, threadId: 400, cpuId: 40000, eventTypeId: 4}}, 49 {HiperfCallChartData: {callchainId: 5, startTs: 5.5, eventCount: 50, threadId: 500, cpuId: 50000, eventTypeId: 5}}, 50 ]); 51 }); 52 it('HiperfCallChartReceiver01', function () { 53 const args = { 54 recordStartNS: 1000, 55 endNS: 3000, 56 startNS: 2000, 57 width: 10 58 }; 59 expect(chartHiperfCallChartDataSql(args)).toBeTruthy(); 60 }); 61 it('HiperfCallChartReceiver02', () => { 62 const mockPostMessage = jest.fn(); 63 global.postMessage = mockPostMessage; 64 hiPerfCallChartDataHandler(data, proc); 65 hiPerfCallChartDataHandler(data2, proc); 66 expect(mockPostMessage).toHaveBeenCalledTimes(1); 67 }); 68 it('HiperfCallChartReceiver03', () => { 69 const mockPostMessage = jest.fn(); 70 global.postMessage = mockPostMessage; 71 hiPerfCallStackCacheHandler(data, proc); 72 hiPerfCallStackCacheHandler(data2, proc); 73 expect(mockPostMessage).toHaveBeenCalledTimes(1); 74 }); 75});