test_individuals_02.js (2613B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test switching to the individuals view when we are in the middle of computing 7 // a dominator tree. 8 9 const { 10 censusState, 11 dominatorTreeState, 12 viewState, 13 individualsState, 14 } = require("resource://devtools/client/memory/constants.js"); 15 const { 16 fetchIndividuals, 17 takeSnapshotAndCensus, 18 computeDominatorTree, 19 } = require("resource://devtools/client/memory/actions/snapshot.js"); 20 const { 21 changeView, 22 } = require("resource://devtools/client/memory/actions/view.js"); 23 24 const EXPECTED_INDIVIDUAL_STATES = [ 25 individualsState.COMPUTING_DOMINATOR_TREE, 26 individualsState.FETCHING, 27 individualsState.FETCHED, 28 ]; 29 30 add_task(async function () { 31 const front = new StubbedMemoryFront(); 32 const heapWorker = new HeapAnalysesClient(); 33 await front.attach(); 34 const store = Store(); 35 const { getState, dispatch } = store; 36 37 equal(getState().individuals, null, "no individuals state by default"); 38 39 dispatch(changeView(viewState.CENSUS)); 40 dispatch(takeSnapshotAndCensus(front, heapWorker)); 41 await waitUntilCensusState(store, s => s.census, [censusState.SAVED]); 42 43 const root = getState().snapshots[0].census.report; 44 ok(root, "Should have a census"); 45 46 const reportLeafIndex = findReportLeafIndex(root); 47 ok(reportLeafIndex, "Should get a reportLeafIndex"); 48 49 const snapshotId = getState().snapshots[0].id; 50 ok(snapshotId, "Should have a snapshot id"); 51 52 const breakdown = getState().snapshots[0].census.display.breakdown; 53 ok(breakdown, "Should have a breakdown"); 54 55 // Start computing a dominator tree. 56 57 dispatch(computeDominatorTree(heapWorker, snapshotId)); 58 equal( 59 getState().snapshots[0].dominatorTree.state, 60 dominatorTreeState.COMPUTING, 61 "Should be computing dominator tree" 62 ); 63 64 // Fetch individuals in the middle of computing the dominator tree. 65 66 dispatch( 67 fetchIndividuals(heapWorker, snapshotId, breakdown, reportLeafIndex) 68 ); 69 70 // Wait for each expected state. 71 for (const state of EXPECTED_INDIVIDUAL_STATES) { 72 await waitUntilState(store, s => { 73 return ( 74 s.view.state === viewState.INDIVIDUALS && 75 s.individuals && 76 s.individuals.state === state 77 ); 78 }); 79 ok(true, `Reached state = ${state}`); 80 } 81 82 ok(getState().individuals, "Should have individuals state"); 83 ok(getState().individuals.nodes, "Should have individuals nodes"); 84 ok( 85 !!getState().individuals.nodes.length, 86 "Should have a positive number of nodes" 87 ); 88 89 heapWorker.destroy(); 90 await front.detach(); 91 });