Skip to content

Fix flaky ioredis test #3319

@jsumners-nr

Description

@jsumners-nr

Some time recently, an ioredis test has started failing seemingly at random. The most current instance is https://github.com/newrelic/node-newrelic/actions/runs/17036192786/job/48289159715#step:7:190.

The failing test is:

await t.test('should not add instance attributes to redis segments when disabled', async (t) => {
const { agent, redisClient, HOST_ID } = t.nr
const plan = tspl(t, { plan: 13 })
agent.config.datastore_tracer.instance_reporting.enabled = false
agent.config.datastore_tracer.database_name_reporting.enabled = false
agent.on('transactionFinished', function (tx) {
const root = tx.trace.root
const children = tx.trace.getChildren(root.id)
plan.equal(children.length, 2, 'root has two children')
const [setSegment, getSegment] = children
const setAttrs = setSegment.getAttributes()
const getAttrs = getSegment.getAttributes()
plan.equal(setAttrs.host, undefined)
plan.equal(setAttrs.product, 'Redis')
plan.equal(setAttrs.key, '"testkey"')
plan.equal(setAttrs.port_path_or_id, undefined)
plan.equal(setAttrs.database_name, undefined)
plan.equal(getAttrs.host, undefined)
plan.equal(getAttrs.product, 'Redis')
plan.equal(getAttrs.key, '"testkey"')
plan.equal(getAttrs.port_path_or_id, undefined)
plan.equal(getAttrs.database_name, undefined)
const unscoped = tx.metrics.unscoped
plan.equal(unscoped[`Datastore/instance/Redis/${HOST_ID}`], undefined)
})
helper.runInTransaction(agent, async (transaction) => {
await redisClient.set('testkey', 'testvalue')
const value = await redisClient.get('testkey')
plan.equal(value, 'testvalue', 'should have expected value')
transaction.end()
})
await plan.completed
})

In particular, the value returned from the Redis store seems to be inconsistent:

const value = await redisClient.get('testkey')
plan.equal(value, 'testvalue', 'should have expected value')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions