Skip to content

Commit

Permalink
test: Updated ioredis tests to assert the host metric getting created…
Browse files Browse the repository at this point in the history
… on ioredis calls (#2230)
  • Loading branch information
bizob2828 authored May 29, 2024
1 parent 85b3862 commit 89df06a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/versioned/ioredis/ioredis-3.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ const helper = require('../../lib/agent_helper')
const { removeMatchedModules } = require('../../lib/cache-buster')
require('../../lib/metrics_helper')
const params = require('../../lib/params')
const urltils = require('../../../lib/util/urltils')

// Indicates unique database in Redis. 0-15 supported.
const DB_INDEX = 4

tap.test('ioredis instrumentation', function (t) {
let agent
let redisClient
let METRIC_HOST_NAME
let HOST_ID

t.beforeEach(async function () {
const result = await setup(t)
agent = result.agent
redisClient = result.client
METRIC_HOST_NAME = urltils.isLocalhost(params.redis_host)
? agent.config.getHostnameSafe()
: params.redis_host
HOST_ID = METRIC_HOST_NAME + '/' + params.redis_port
})

t.afterEach(function () {
Expand All @@ -40,6 +47,7 @@ tap.test('ioredis instrumentation', function (t) {
[{ name: 'Datastore/Redis/all' }],
[{ name: 'Datastore/operation/Redis/set' }]
]
expected['Datastore/instance/Redis/' + HOST_ID] = 2
t.assertMetrics(tx.metrics, expected, false, false)
t.end()
})
Expand Down
8 changes: 8 additions & 0 deletions test/versioned/ioredis/ioredis.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ const tap = require('tap')
const helper = require('../../lib/agent_helper')
require('../../lib/metrics_helper')
const params = require('../../lib/params')
const urltils = require('../../../lib/util/urltils')

// Indicates unique database in Redis. 0-15 supported.
const DB_INDEX = 3

tap.test('ioredis instrumentation', (t) => {
let agent = null
let redisClient = null
let METRIC_HOST_NAME
let HOST_ID

t.autoend()
t.beforeEach(async () => {
agent = helper.instrumentMockedAgent()
const Redis = require('ioredis')
redisClient = new Redis(params.redis_port, params.redis_host)
await helper.flushRedisDb(redisClient, DB_INDEX)
METRIC_HOST_NAME = urltils.isLocalhost(params.redis_host)
? agent.config.getHostnameSafe()
: params.redis_host
HOST_ID = METRIC_HOST_NAME + '/' + params.redis_port

await new Promise(async (resolve, reject) => {
redisClient.select(DB_INDEX, (err) => {
Expand All @@ -48,6 +55,7 @@ tap.test('ioredis instrumentation', (t) => {
[{ name: 'Datastore/Redis/all' }],
[{ name: 'Datastore/operation/Redis/set' }]
]
expected['Datastore/instance/Redis/' + HOST_ID] = 2

t.assertMetrics(tx.metrics, expected, false, false)
t.end()
Expand Down

0 comments on commit 89df06a

Please sign in to comment.