Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests): fix memory leak, intermittent failures #1168

Merged
merged 17 commits into from
May 12, 2020

Conversation

tay1orjones
Copy link
Member

Closes #1143

Summary

  • Refactored a lot of problematic tests that were never getting cleaned up by node's garbage collector, causing the heap size to increase and sometimes give out of memory errors.
  • Fixed async tests that were silently failing. The promise rejection was not being caught by jest due to how the tests were configured.

Change List (commits, features, bugs, etc)

  • Update to use jsdom 16
  • Properly mock and clean up timers, lodash debounce, prototype methods
  • Refactor async tests to resolve
  • Many other small fixes you'll see in the file view

Acceptance Test (how to verify the PR)

  • Run the test suite locally
  • View the results of the test suite in Travis CI
  • Tests should pass every time, heap usage should be relatively flat (~200-300mb from one another). Previously the heap started at ~100mb and ended >1000mb 😬

Results in my local console:

Log of running tests serially
❯ yarn test:base --logHeapUsage --silent --runInBand --no-cache
yarn run v1.12.3
$ cross-env TZ=America/Chicago jest --testPathPattern='.*\.test\.js(x)?' --coverage --logHeapUsage --silent --runInBand --no-cache
(node:41717) ExperimentalWarning: The fs.promises API is experimental
 PASS  src/components/Table/tableReducer.test.jsx (11.563s, 279 MB heap size)
 PASS  src/components/Table/Table.test.jsx (290 MB heap size)
 PASS  src/components/TableCard/TableCard.test.jsx (272 MB heap size)
 PASS  src/components/List/HierarchyList/HierarchyList.test.jsx (14.893s, 579 MB heap size)
 PASS  src/components/Table/TableHead/TableHead.test.jsx (299 MB heap size)
 PASS  src/components/Header/Header.test.jsx (389 MB heap size)
 PASS  src/components/Card/DataStateRenderer.test.jsx (459 MB heap size)
 PASS  src/components/Dashboard/Dashboard.test.jsx (334 MB heap size)
 PASS  src/components/DateTimePicker/DateTimePicker.test.jsx (407 MB heap size)
 PASS  src/components/TimeSeriesCard/timeSeriesUtils.test.js (460 MB heap size)
 PASS  src/components/List/SimpleList/SimpleList.test.jsx (356 MB heap size)
 PASS  src/components/TimePickerSpinner/TimePickerSpinner.test.jsx (444 MB heap size)
 PASS  src/components/Card/Card.test.jsx (533 MB heap size)
 PASS  src/components/TileGallery/TileGallery.test.jsx (394 MB heap size)
 PASS  src/components/ImageCard/ImageHotspots.test.jsx (458 MB heap size)
 PASS  src/components/FileDrop/FileDrop.test.jsx (523 MB heap size)
 PASS  src/components/WizardInline/StatefulWizard.test.jsx (614 MB heap size)
 PASS  src/components/TileCatalogNew/TileCatalogNew.test.jsx (407 MB heap size)
 PASS  src/components/Table/TableDetailWizard/StatefulTableDetailWizard.test.jsx (501 MB heap size)
 PASS  src/components/StorybookSnapshots.test.js (32.151s, 709 MB heap size)
 PASS  src/components/Table/TableCellRenderer/TableCellRenderer.test.jsx (780 MB heap size)
 PASS  src/components/SideNav/SideNav.test.jsx (833 MB heap size)
 PASS  src/utils/__tests__/publicAPI.test.js (943 MB heap size)
 PASS  src/components/Table/TableHead/ColumnHeaderRow/ColumnHeaderRow.test.jsx (594 MB heap size)
 PASS  src/components/WizardModal/WizardModal.test.jsx (673 MB heap size)
 PASS  src/components/TileCatalog/tileCatalogReducer.test.js (716 MB heap size)
 PASS  src/components/Table/TableBody/TableBodyRow/TableBodyRow.test.jsx (790 MB heap size)
 PASS  src/components/TileCatalog/StatefulTileCatalog.test.jsx (866 MB heap size)
 PASS  src/components/Dashboard/CardRenderer.test.jsx (608 MB heap size)
 PASS  src/components/PageWizard/PageWizard.test.jsx (702 MB heap size)
 PASS  src/components/PageTitleBar/PageTitleBar.test.jsx (778 MB heap size)
 PASS  src/components/Table/TableBody/RowActionsCell/RowActionsCell.test.jsx (848 MB heap size)
 PASS  src/components/PageWizard/StatefulPageWizard.test.jsx (946 MB heap size)
 PASS  src/components/BarChartCard/BarChartCard.test.jsx (661 MB heap size)
 PASS  src/utils/__tests__/componentUtilityFunctions.test.js (700 MB heap size)
 PASS  src/components/IconSwitch/IconSwitch.test.jsx (764 MB heap size)
 PASS  src/components/Table/StatefulTableMockReducers.test.jsx (905 MB heap size)
 PASS  src/components/TimeSeriesCard/TimeSeriesCard.test.jsx (989 MB heap size)
 PASS  src/components/GaugeCard/GaugeCard.test.jsx (278 MB heap size)
 PASS  src/components/List/ListItem/ListItem.test.jsx (361 MB heap size)
 PASS  src/components/Breadcrumb/Breadcrumb.test.jsx (316 MB heap size)
 PASS  src/components/Card/CardRangePicker.test.jsx (397 MB heap size)
 PASS  src/components/ResourceList/ResourceList.test.jsx (458 MB heap size)
 PASS  src/components/ValueCard/ValueCard.test.jsx (535 MB heap size)
 PASS  src/components/List/List.test.jsx (403 MB heap size)
 PASS  src/components/SimplePagination/SimplePagination.test.jsx (458 MB heap size)
 PASS  src/components/Table/TableHead/FilterHeaderRow/FilterHeaderRow.test.jsx (521 MB heap size)
 PASS  src/components/Dashboard/DashboardGrid.test.jsx (577 MB heap size)
 PASS  src/components/ImageCard/ImageHotspotsRender.test.jsx (417 MB heap size)
 PASS  src/components/ListCard/ListCard.test.jsx (491 MB heap size)
 PASS  src/components/Table/TableDetailWizard/TableDetailWizard.test.jsx (571 MB heap size)
 PASS  src/components/Header/HeaderAction/HeaderActionMenu.test.jsx (334 MB heap size)
 PASS  src/components/WizardInline/WizardInline.test.jsx (448 MB heap size)
 PASS  src/components/Table/Pagination.test.jsx (526 MB heap size)
 PASS  src/components/Accordion/AccordionItemDefer.test.jsx (359 MB heap size)
 PASS  src/components/ComposedModal/ComposedModal.test.jsx (432 MB heap size)
 PASS  src/components/Table/StatefulTable.test.jsx (370 MB heap size)
 PASS  src/components/WizardInline/WizardFooter/WizardFooter.test.jsx (427 MB heap size)
 PASS  src/components/Page/PageHero.test.jsx (493 MB heap size)
 PASS  src/components/ComposedStructuredList/ComposedStructuredList.test.jsx (558 MB heap size)
 PASS  src/utils/__tests__/cardUtilityFunctions.test.js (598 MB heap size)
 PASS  src/components/NavigationBar/NavigationBar.test.jsx (376 MB heap size)
 PASS  src/components/ProgressIndicator/ProgressIndicator.test.jsx (443 MB heap size)
 PASS  src/components/TileCatalog/TileCatalog.test.jsx (527 MB heap size)
 PASS  src/components/List/ListHeader/ListHeader.test.jsx (597 MB heap size)
 PASS  src/components/ImageCard/CardIcon.test.jsx (399 MB heap size)
 PASS  src/components/Button/Button.test.jsx (464 MB heap size)
 PASS  src/components/Table/TableDetailWizard/TableDetailWizardHeader/TableDetailWizardHeader.test.jsx (528 MB heap size)
 PASS  src/components/Page/PageWorkArea.test.jsx (568 MB heap size)
 PASS  src/components/AddCard/AddCard.test.jsx (633 MB heap size)

=============================== Coverage summary ===============================
Statements   : 93.73% ( 3033/3236 )
Branches     : 84.49% ( 2266/2682 )
Functions    : 90.08% ( 863/958 )
Lines        : 93.87% ( 2912/3102 )
================================================================================

Test Suites: 70 passed, 70 total
Tests:       711 passed, 711 total
Snapshots:   288 passed, 288 total
Time:        165.81s
✨  Done in 170.14s.
Log of running tests in parallel (local default)
❯ yarn test:base --logHeapUsage --silent --no-cache
yarn run v1.12.3
$ cross-env TZ=America/Chicago jest --testPathPattern='.*\.test\.js(x)?' --coverage --logHeapUsage --silent --no-cache
(node:41998) ExperimentalWarning: The fs.promises API is experimental
(node:42007) ExperimentalWarning: The fs.promises API is experimental
(node:42000) ExperimentalWarning: The fs.promises API is experimental
(node:42006) ExperimentalWarning: The fs.promises API is experimental
(node:42008) ExperimentalWarning: The fs.promises API is experimental
(node:42003) ExperimentalWarning: The fs.promises API is experimental
(node:42002) ExperimentalWarning: The fs.promises API is experimental
(node:41999) ExperimentalWarning: The fs.promises API is experimental
(node:42004) ExperimentalWarning: The fs.promises API is experimental
(node:42005) ExperimentalWarning: The fs.promises API is experimental
(node:42001) ExperimentalWarning: The fs.promises API is experimental
 PASS  src/components/TimeSeriesCard/timeSeriesUtils.test.js (10.715s, 143 MB heap size)
 PASS  src/components/Card/DataStateRenderer.test.jsx (13.822s, 141 MB heap size)
 PASS  src/components/Header/Header.test.jsx (14.589s, 143 MB heap size)
 PASS  src/components/DateTimePicker/DateTimePicker.test.jsx (16.884s, 141 MB heap size)
 PASS  src/components/List/SimpleList/SimpleList.test.jsx (17.613s, 152 MB heap size)
 PASS  src/components/TimePickerSpinner/TimePickerSpinner.test.jsx (7.127s, 177 MB heap size)
 PASS  src/components/Table/TableHead/TableHead.test.jsx (18.535s, 197 MB heap size)
 PASS  src/components/Card/Card.test.jsx (6.993s, 186 MB heap size)
 PASS  src/components/ImageCard/ImageHotspots.test.jsx (5.116s, 235 MB heap size)
 PASS  src/components/FileDrop/FileDrop.test.jsx (240 MB heap size)
 PASS  src/components/Table/TableCellRenderer/TableCellRenderer.test.jsx (204 MB heap size)
 PASS  src/components/TileCatalogNew/TileCatalogNew.test.jsx (7.06s, 205 MB heap size)
 PASS  src/components/WizardInline/StatefulWizard.test.jsx (8.54s, 221 MB heap size)
 PASS  src/components/Table/Table.test.jsx (27.455s, 204 MB heap size)
 PASS  src/components/Table/TableDetailWizard/StatefulTableDetailWizard.test.jsx (7.378s, 295 MB heap size)
 PASS  src/components/SideNav/SideNav.test.jsx (268 MB heap size)
 PASS  src/components/Table/tableReducer.test.jsx (28.605s, 181 MB heap size)
 PASS  src/components/Table/TableHead/ColumnHeaderRow/ColumnHeaderRow.test.jsx (6.18s, 219 MB heap size)
 PASS  src/components/TileCatalog/tileCatalogReducer.test.js (240 MB heap size)
 PASS  src/components/WizardModal/WizardModal.test.jsx (6.377s, 190 MB heap size)
 PASS  src/components/TileCatalog/StatefulTileCatalog.test.jsx (6.36s, 183 MB heap size)
 PASS  src/components/Table/TableBody/TableBodyRow/TableBodyRow.test.jsx (6.597s, 241 MB heap size)
 PASS  src/components/TableCard/TableCard.test.jsx (38.02s, 178 MB heap size)
 PASS  src/components/Table/TableBody/RowActionsCell/RowActionsCell.test.jsx (245 MB heap size)
 PASS  src/components/PageTitleBar/PageTitleBar.test.jsx (5.13s, 273 MB heap size)
 PASS  src/components/PageWizard/PageWizard.test.jsx (6.736s, 252 MB heap size)
 PASS  src/utils/__tests__/componentUtilityFunctions.test.js (290 MB heap size)
 PASS  src/components/IconSwitch/IconSwitch.test.jsx (211 MB heap size)
 PASS  src/components/PageWizard/StatefulPageWizard.test.jsx (7.629s, 229 MB heap size)
 PASS  src/components/List/ListItem/ListItem.test.jsx (196 MB heap size)
 PASS  src/components/GaugeCard/GaugeCard.test.jsx (6.75s, 219 MB heap size)
 PASS  src/components/Dashboard/Dashboard.test.jsx (51.939s, 331 MB heap size)
 PASS  src/components/BarChartCard/BarChartCard.test.jsx (13.96s, 352 MB heap size)
 PASS  src/components/Card/CardRangePicker.test.jsx (301 MB heap size)
 PASS  src/components/ResourceList/ResourceList.test.jsx (202 MB heap size)
 PASS  src/components/ValueCard/ValueCard.test.jsx (5.27s, 458 MB heap size)
 PASS  src/components/SimplePagination/SimplePagination.test.jsx (251 MB heap size)
 PASS  src/components/TimeSeriesCard/TimeSeriesCard.test.jsx (18.228s, 384 MB heap size)
 PASS  src/components/Table/StatefulTableMockReducers.test.jsx (18.95s, 376 MB heap size)
 PASS  src/components/Dashboard/DashboardGrid.test.jsx (301 MB heap size)
 PASS  src/components/Table/TableHead/FilterHeaderRow/FilterHeaderRow.test.jsx (273 MB heap size)
 PASS  src/components/ListCard/ListCard.test.jsx (244 MB heap size)
 PASS  src/components/ImageCard/ImageHotspotsRender.test.jsx (5.678s, 223 MB heap size)
 PASS  src/components/Header/HeaderAction/HeaderActionMenu.test.jsx (362 MB heap size)
 PASS  src/components/Table/TableDetailWizard/TableDetailWizard.test.jsx (6.362s, 279 MB heap size)
 PASS  src/components/Table/Pagination.test.jsx (301 MB heap size)
 PASS  src/components/Accordion/AccordionItemDefer.test.jsx (315 MB heap size)
 PASS  src/components/Dashboard/CardRenderer.test.jsx (35.729s, 322 MB heap size)
 PASS  src/components/WizardInline/WizardInline.test.jsx (6.622s, 369 MB heap size)
 PASS  src/components/ComposedModal/ComposedModal.test.jsx (234 MB heap size)
 PASS  src/components/WizardInline/WizardFooter/WizardFooter.test.jsx (380 MB heap size)
 PASS  src/utils/__tests__/cardUtilityFunctions.test.js (279 MB heap size)
 PASS  src/components/Page/PageHero.test.jsx (385 MB heap size)
 PASS  src/components/ComposedStructuredList/ComposedStructuredList.test.jsx (247 MB heap size)
 PASS  src/components/List/HierarchyList/HierarchyList.test.jsx (72.208s, 304 MB heap size)
 PASS  src/components/ProgressIndicator/ProgressIndicator.test.jsx (340 MB heap size)
 PASS  src/components/NavigationBar/NavigationBar.test.jsx (298 MB heap size)
 PASS  src/components/TileGallery/TileGallery.test.jsx (59.106s, 345 MB heap size)
 PASS  src/components/List/ListHeader/ListHeader.test.jsx (321 MB heap size)
 PASS  src/components/ImageCard/CardIcon.test.jsx (248 MB heap size)
 PASS  src/components/Page/PageWorkArea.test.jsx (224 MB heap size)
 PASS  src/components/Table/StatefulTable.test.jsx (8.437s, 309 MB heap size)
 PASS  src/components/Button/Button.test.jsx (403 MB heap size)
 PASS  src/utils/__tests__/publicAPI.test.js (50.029s, 257 MB heap size)
 PASS  src/components/Table/TableDetailWizard/TableDetailWizardHeader/TableDetailWizardHeader.test.jsx (367 MB heap size)
 PASS  src/components/TileCatalog/TileCatalog.test.jsx (238 MB heap size)
 PASS  src/components/AddCard/AddCard.test.jsx (259 MB heap size)
 PASS  src/components/Breadcrumb/Breadcrumb.test.jsx (36.147s, 250 MB heap size)
 PASS  src/components/List/List.test.jsx (30.368s, 320 MB heap size)
 PASS  src/components/StorybookSnapshots.test.js (83.545s, 549 MB heap size)

=============================== Coverage summary ===============================
Statements   : 93.73% ( 3033/3236 )
Branches     : 84.49% ( 2266/2682 )
Functions    : 90.08% ( 863/958 )
Lines        : 93.87% ( 2912/3102 )
================================================================================

Test Suites: 70 passed, 70 total
Tests:       711 passed, 711 total
Snapshots:   288 passed, 288 total
Time:        115.758s
✨  Done in 120.37s.

@netlify
Copy link

netlify bot commented May 8, 2020

Deploy preview for carbon-addons-iot-react ready!

Built with commit 8c07320

https://deploy-preview-1168--carbon-addons-iot-react.netlify.app

@netlify
Copy link

netlify bot commented May 8, 2020

Deploy preview for carbon-addons-iot-react ready!

Built with commit d87c2e8

https://deploy-preview-1168--carbon-addons-iot-react.netlify.app

Copy link
Contributor

@sstone2423 sstone2423 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job finding all of these! We'll go through monitor to fix these same issues

config/jest/setupTest.js Outdated Show resolved Hide resolved
Copy link
Contributor

@scottdickerson scottdickerson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I did put one question in.

@davidicus davidicus merged commit 3bd2f51 into master May 12, 2020
@tay1orjones
Copy link
Member Author

🎉 This PR is included in version 2.77.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tay1orjones tay1orjones deleted the investigate-jest-failures branch May 12, 2020 14:38
@tay1orjones tay1orjones mentioned this pull request Jul 8, 2020
32 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[tests] leaking memory, tests silently failing, intermittent failures in CI
4 participants