Skip to content

Commit

Permalink
Fix results assumptions (#610)
Browse files Browse the repository at this point in the history
* test refactor: separate waitForResults for other uses

* test fix: wait for ingest to finish before waiting for any results

* test fix: remove unnecessary promise chain

* test fix: initial histogram should just have > 0 rect elements

* test fix: only do precise counting after setting Whole Space to force a refresh

* test fix: wait for results to be redrawn after setting span

* test chore: update comment and message for clarification

* test fix: change this count for whole space

* test fix: remove unneded histogram data check value
  • Loading branch information
mikesbrown authored Apr 14, 2020
1 parent d95f931 commit 05b420e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
11 changes: 8 additions & 3 deletions itest/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ export const toggleOptimizations = async (app: Application) => {
await app.client.click(selectors.settings.button)
}

export const waitForResults = (app: Application) =>
appStep("wait for results viewer to appear", () =>
app.client.waitForVisible(selectors.viewer.results_base)
)

export const pcapIngestSample = async (app: Application) => {
// Ingest a PCAP and wait until we see derived records.
const pcapFile = path.normalize(path.join(__dirname, "..", "sample.pcap"))
Expand All @@ -310,15 +315,15 @@ export const pcapIngestSample = async (app: Application) => {
await appStep("choose file", () =>
app.client.chooseFile(selectors.pcaps.fileInput, pcapFile)
)
await appStep("wait for viewer to appear", () =>
app.client.waitForVisible(selectors.viewer.results_base)
)

await appStep("wait for ingest to finish", () =>
retryUntil(
() => app.client.isExisting(selectors.status.ingestProgress),
(ingesting) => ingesting === false
)
)

await waitForResults(app)
}

export const takeScreenshot = async (app: Application) => {
Expand Down
6 changes: 2 additions & 4 deletions itest/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ export const dataSets = {
// last 30 minutes to last hour, some of these numbers may become invalid.
sample: {
histogram: {
defaultDistinctPaths: 8,
defaultRectsPerClass: 11,
defaultTotalRectCount: 8 * 11,
rectAttrMin: 0,
rectAttrMax: 1000,
wholeSpaceDistinctPaths: 8
wholeSpaceDistinctPaths: 8,
wholeSpaceRectsPerClass: 11
},
spaceName: "sample.pcap.brim"
}
Expand Down
42 changes: 16 additions & 26 deletions itest/tests/histogram.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
newAppInstance,
pcapIngestSample,
startApp,
setSpan
setSpan,
waitForResults
} from "../lib/app.js"
import {retryUntil} from "../lib/control.js"
import {handleError, stdTest} from "../lib/jest.js"
Expand Down Expand Up @@ -65,31 +66,30 @@ describe("Histogram tests", () => {
LOG.debug("Pre-login")
pcapIngestSample(app)
.then(async () => {
LOG.debug("Checking number of histogram rect elements")
let result = await retryUntil(
LOG.debug("Checking a histogram appears")
// Verify that a histogram of at least *partial data* is
// present.
await retryUntil(
() => app.client.$$(selectors.histogram.rectElem),
(rectElements) =>
rectElements.length ===
dataSets.sample.histogram.defaultTotalRectCount
(rectElements) => rectElements.length > 0
).catch(() => {
throw new Error(
"Histogram did not render the expected number of rect elements"
)
throw new Error("Initial histogram did not render any rect elements")
})
LOG.debug("Got number of histogram rect elements")
return result
})
.then(async () => {
// Assuming we properly loaded data into a default space, we
// we must wait until the components of the histogram are rendered. This
// means we must wait for a number of g elements and rect elements. Those
// elements depend on both the dataset itself and the product's behavior.
LOG.debug("Getting number of distinct _paths")
// Set to "Whole Space" to make sure this entire histogram is redrawn.
await setSpan(app, "Whole Space")
await waitForResults(app)
// Just count a higher number of _paths, not all ~1500 rect elements.
LOG.debug("Checking rect elements in Whole Space")
let pathClasses = await retryUntil(
() => app.client.getAttribute(selectors.histogram.gElem, "class"),
(pathClasses) =>
pathClasses.length ===
dataSets.sample.histogram.defaultDistinctPaths
dataSets.sample.histogram.wholeSpaceDistinctPaths
)
LOG.debug("Got number of distinct _paths")
expect(pathClasses.sort()).toMatchSnapshot()
Expand All @@ -109,29 +109,19 @@ describe("Histogram tests", () => {
// Whereas we just counted g elements before, this breaks down rect
// elements within their g parent, ensuring rect elements are of the
// proper _path.
dataSets.sample.histogram.defaultDistinctPaths
dataSets.sample.histogram.wholeSpaceDistinctPaths
)
LOG.debug("Ensuring all rect elements' attributes are sane")
allRectValues.forEach((pathClass) => {
// The 4 comes from each of x, y, width, height for a rect element.
expect(pathClass.length).toBe(4)
pathClass.forEach((attr) => {
expect(attr.length).toBe(
dataSets.sample.histogram.defaultRectsPerClass
dataSets.sample.histogram.wholeSpaceRectsPerClass
)
})
})
LOG.debug("Ensured all rect elements' attributes are sane")
// Now set to "Whole Space" to make sure this histogram is redrawn.
await setSpan(app, "Whole Space")
// Just count a higher number of _paths, not all ~1500 rect elements.
LOG.debug("Checking rect elements in Whole Space")
await retryUntil(
() => app.client.getAttribute(selectors.histogram.gElem, "class"),
(pathClasses) =>
pathClasses.length ===
dataSets.sample.histogram.wholeSpaceDistinctPaths
)
done()
})
.catch((err) => {
Expand Down

0 comments on commit 05b420e

Please sign in to comment.