test_action-take-census.js (2317B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests the async reducer responding to the action `takeCensus(heapWorker, snapshot)` 8 */ 9 10 var { 11 snapshotState: states, 12 censusDisplays, 13 censusState, 14 viewState, 15 } = require("resource://devtools/client/memory/constants.js"); 16 var actions = require("resource://devtools/client/memory/actions/snapshot.js"); 17 var { 18 changeView, 19 } = require("resource://devtools/client/memory/actions/view.js"); 20 21 // This tests taking a census on a snapshot that is still being read, which 22 // triggers an assertion failure. 23 EXPECTED_DTU_ASSERT_FAILURE_COUNT = 1; 24 25 add_task(async function () { 26 const front = new StubbedMemoryFront(); 27 const heapWorker = new HeapAnalysesClient(); 28 await front.attach(); 29 const store = Store(); 30 31 store.dispatch(changeView(viewState.CENSUS)); 32 33 store.dispatch(actions.takeSnapshot(front)); 34 await waitUntilState(store, () => { 35 const snapshots = store.getState().snapshots; 36 return snapshots.length === 1 && snapshots[0].state === states.SAVED; 37 }); 38 39 let snapshot = store.getState().snapshots[0]; 40 equal(snapshot.census, null, "No census data exists yet on the snapshot."); 41 42 // Test error case of wrong state. 43 store.dispatch(actions.takeCensus(heapWorker, snapshot.id)); 44 await waitUntilState(store, () => store.getState().errors.length === 1); 45 46 dumpn("Found error: " + store.getState().errors[0]); 47 ok( 48 /Assertion failure/.test(store.getState().errors[0]), 49 "Error thrown when taking a census of a snapshot that has not been read." 50 ); 51 52 store.dispatch(actions.readSnapshot(heapWorker, snapshot.id)); 53 await waitUntilState( 54 store, 55 () => store.getState().snapshots[0].state === states.READ 56 ); 57 58 store.dispatch(actions.takeCensus(heapWorker, snapshot.id)); 59 await waitUntilCensusState(store, s => s.census, [censusState.SAVING]); 60 await waitUntilCensusState(store, s => s.census, [censusState.SAVED]); 61 62 snapshot = store.getState().snapshots[0]; 63 ok(snapshot.census, "Snapshot has census after saved census"); 64 ok(snapshot.census.report.children.length, "Census is in tree node form"); 65 equal( 66 snapshot.census.display, 67 censusDisplays.coarseType, 68 "Snapshot stored correct display used for the census" 69 ); 70 });