Skip to content

assert: improve assert call tracker

This is still WIP and I still have to write a lot of tests and update the documentation but I wanted to open the PR and get first feedback, since it's a bigger change.

It is meant to improve the new assert.Calltracker API and the new API is also meant to be a drop in replacement for our original internal common.mustCall() (I already replaced it here).

Commits:

test: fix tracked functions in test-inspector-workers-flat-list.js

The common.mustCall() function is not strict enough to detect that this test is actually failing it's verify step. The error is printed to stdout and it's silently ignored.

test: fix test/parallel/test-cluster-master-error.js

This test failed on master but it was not detected so far due to common.mustCall() being lenient about errors.

It was not detected due to the silent option used while spawing the process. That is changed to pass through information to the main process. The expected function calls is now also corrected.

test: fix test/parallel/test-child-process-fork-getconnections.js

The former mustCall() check did not properly verify that the function was indeed called the correct number of times. That is fixed.

test: fix test/parallel/test-child-process-fork-net.js

The former implementation had silent errors. This fixes the test by correcting the number of times the individual functions are called.

assert: improve tracker implementation

This is mainly a replacement of the current Calltracker API. This implementations goals are a easier, more straight forward API, being less error prone and providing more powerful options.

It implements the "minimum" mode, "verifyOnExit" opt-in and a option to deactivate early checks.

It contains more debugging information such as call frames and combined stack traces.

On top of that, it's going to check for the correct API implementation. It will throw an error in case a user missed to call .verify().

The API is simpler to use by straight forward using the passed back function. There is no need to create a class instance anymore.

With this implementation it is possible to replace the internal common.mustCall() implementation without any further modifications. It turned out that the new implementation is stricter and using it brought up a couple of bugs in the tests that were also fixed.

test: use assert.trackCalls() internally in common.mustCall()

This changes the internal common.mustCall() and common.mustCallAtLeast() functions to use assert.trackCalls(). The assert API is a bit more powerful (providing more debugging information) than the current application. By switching to the assert API the API itself is also heavily tested against memory leaks.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading