Skip to content

Commit 5e3f0a8

Browse files
authored
test: Fixed conflict between ioredis and ioredis-esm by running flushdb instead of flushall to avoid index getting removed mid test (#3464)
1 parent 4deb6d8 commit 5e3f0a8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

test/versioned/ioredis-esm/ioredis.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ test('ioredis instrumentation', async (t) => {
2424
const redis = await import('ioredis')
2525
const Redis = redis.default || redis.Redis
2626
const redisClient = new Redis(params.redis_port, params.redis_host)
27-
await redisClient.flushall()
2827
const METRIC_HOST_NAME = urltils.isLocalhost(params.redis_host)
2928
? agent.config.getHostnameSafe()
3029
: params.redis_host
@@ -41,10 +40,13 @@ test('ioredis instrumentation', async (t) => {
4140
}
4241
})
4342

44-
t.afterEach((ctx) => {
43+
t.afterEach(async (ctx) => {
4544
const { agent, redisClient } = ctx.nr
4645
helper.unloadAgent(agent)
4746
removeModules(['ioredis'])
47+
// re-select the default index for suite as some tests change it
48+
await redisClient.select(DB_INDEX)
49+
await redisClient.flushdb()
4850
redisClient.disconnect()
4951
})
5052

@@ -194,6 +196,8 @@ test('ioredis instrumentation', async (t) => {
194196
await redisClient.select(SELECTED_DB)
195197
await redisClient.set(`${redisKey}2`, 'testvalue')
196198
transaction.end()
199+
// flushing index 8
200+
await redisClient.flushdb()
197201
})
198202
await plan.completed
199203
})

test/versioned/ioredis/ioredis.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ test('ioredis instrumentation', async (t) => {
2323
const { version: pkgVersion } = require('ioredis/package.json')
2424
const Redis = require('ioredis')
2525
const redisClient = new Redis(params.redis_port, params.redis_host)
26-
await redisClient.flushall()
2726
const METRIC_HOST_NAME = urltils.isLocalhost(params.redis_host)
2827
? agent.config.getHostnameSafe()
2928
: params.redis_host
@@ -41,10 +40,13 @@ test('ioredis instrumentation', async (t) => {
4140
}
4241
})
4342

44-
t.afterEach((ctx) => {
43+
t.afterEach(async (ctx) => {
4544
const { agent, redisClient } = ctx.nr
4645
helper.unloadAgent(agent)
4746
removeModules(['ioredis'])
47+
// re-select the default index for suite as some tests change it
48+
await redisClient.select(DB_INDEX)
49+
await redisClient.flushdb()
4850
redisClient.disconnect()
4951
})
5052

@@ -176,7 +178,6 @@ test('ioredis instrumentation', async (t) => {
176178
const { agent, redisClient, redisKey } = t.nr
177179
const plan = tspl(t, { plan: 7 })
178180
const SELECTED_DB = 5
179-
180181
agent.on('transactionFinished', function (tx) {
181182
const root = tx.trace.root
182183
const children = tx.trace.getChildren(root.id)
@@ -196,6 +197,8 @@ test('ioredis instrumentation', async (t) => {
196197
await redisClient.select(SELECTED_DB)
197198
await redisClient.set(`${redisKey}2`, 'testvalue')
198199
transaction.end()
200+
// flushing index 5
201+
await redisClient.flushdb()
199202
})
200203
await plan.completed
201204
})

0 commit comments

Comments
 (0)