chore: Fixed mongodb-esm tests in combination with security agent #2444
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow up to #2434. After the tests were restored, we started having CI failures when the security agent tests are run. See https://github.com/newrelic/node-newrelic/actions/runs/10245880392 for the first failure.
What I discovered is that the test:
node-newrelic/test/versioned/mongodb-esm/collection-common.mjs
Line 69 in f1dd8e7
Should be ordered before the test:
node-newrelic/test/versioned/mongodb-esm/collection-common.mjs
Line 60 in f1dd8e7
This is due to the
.clear()
in:node-newrelic/test/versioned/mongodb-esm/collection-common.mjs
Lines 53 to 58 in f1dd8e7
In short: the
.clear()
removes theSupportability/API/instrumentDatastore
segment added by the security agent when themongodb
module is loaded.However, swapping the order is not enough. We still end up with global state issues due to the structure of the tests. Initially, I attempted to figure out how to fix the problem within the existing structure, but the tests were just too complicated for me to put them all together in my head. Given all of this, I decided it best to go ahead and convert the whole
mongodb-esm
test suite to usenode:test
instead oftap
. I was needing to do significant restructuring anyway to get the tests working, and I needed to deconstruct them to understand them. So it made sense to me to solve both jobs in one go.I maintained a fair bit of the abstraction present in these tests, but I refactored what is left such that it fits with test-scoped "globals" instead of suite scoped globals. Some of the abstraction I removed. As an example, the
db.test.mjs
suite no longer passes off each test to adbTest
function that internally ran two separate tests. I'm not convinced every test in the suite needs to run with and without transaction tests, but I carried them through. In my view, the structure in this PR is easier to reason through (even though a lot of the tests are still difficult to follow).