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

chore: Fixed mongodb-esm tests in combination with security agent #2444

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 deletions test/versioned/mongodb-esm/bulk.tap.mjs

This file was deleted.

79 changes: 79 additions & 0 deletions test/versioned/mongodb-esm/bulk.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import test from 'node:test'
import assert from 'node:assert'
import helper from '../../lib/agent_helper.js'
import common from '../mongodb/common.js'
import { beforeEach, afterEach } from './test-hooks.mjs'
import { getValidatorCallback } from './test-assertions.mjs'

const {
ESM: { STATEMENT_PREFIX }
} = common

test('unordered bulk operations', async (t) => {
t.beforeEach(beforeEach)
t.afterEach(afterEach)

await t.test('should generate the correct metrics and segments', (t, end) => {
const { agent, collection } = t.nr
const segments = [`${STATEMENT_PREFIX}/unorderedBulk/batch`, 'Callback: done']
const metrics = ['unorderedBulk']

helper.runInTransaction(agent, (tx) => {
tx.name = common.TRANSACTION_NAME
const bulk = collection.initializeUnorderedBulkOp()
bulk.find({ i: 1 }).updateOne({ $set: { foo: 'bar' } })
bulk.find({ i: 2 }).updateOne({ $set: { foo: 'bar' } })
bulk.execute(getValidatorCallback({ t, tx, metrics, segments, end }))
})
})

await t.test('should not error outside of a transaction', (t, end) => {
const { agent, collection } = t.nr
assert.equal(agent.getTransaction(), undefined, 'should not be in a transaction')
const bulk = collection.initializeUnorderedBulkOp()
bulk.find({ i: 1 }).updateOne({ $set: { foo: 'bar' } })
bulk.find({ i: 2 }).updateOne({ $set: { foo: 'bar' } })
bulk.execute(function done(error) {
assert.equal(error, undefined, 'running test should not error')
assert.equal(agent.getTransaction(), undefined, 'should not somehow gain a transaction')
end()
})
})
})

test('ordered bulk operations', async (t) => {
t.beforeEach(beforeEach)
t.afterEach(afterEach)

await t.test('should generate the correct metrics and segments', (t, end) => {
const { agent, collection } = t.nr
const segments = [`${STATEMENT_PREFIX}/orderedBulk/batch`, 'Callback: done']
const metrics = ['orderedBulk']

helper.runInTransaction(agent, (tx) => {
tx.name = common.TRANSACTION_NAME
const bulk = collection.initializeOrderedBulkOp()
bulk.find({ i: 1 }).updateOne({ $set: { foo: 'bar' } })
bulk.find({ i: 2 }).updateOne({ $set: { foo: 'bar' } })
bulk.execute(getValidatorCallback({ t, tx, metrics, segments, end }))
})
})

await t.test('should not error outside of a transaction', (t, end) => {
const { agent, collection } = t.nr
assert.equal(agent.getTransaction(), undefined, 'should not be in a transaction')
const bulk = collection.initializeOrderedBulkOp()
bulk.find({ i: 1 }).updateOne({ $set: { foo: 'bar' } })
bulk.find({ i: 2 }).updateOne({ $set: { foo: 'bar' } })
bulk.execute(function done(error) {
assert.equal(error, undefined, 'running test should not error')
assert.equal(agent.getTransaction(), undefined, 'should not somehow gain a transaction')
end()
})
})
})
210 changes: 0 additions & 210 deletions test/versioned/mongodb-esm/collection-common.mjs

This file was deleted.

Loading
Loading