@@ -29,11 +29,13 @@ test('ioredis instrumentation', async (t) => {
2929 ? agent . config . getHostnameSafe ( )
3030 : params . redis_host
3131 const HOST_ID = METRIC_HOST_NAME + '/' + params . redis_port
32+ const redisKey = helper . randomString ( 'redis-key' )
3233
3334 await redisClient . select ( DB_INDEX )
3435 ctx . nr = {
3536 agent,
3637 redisClient,
38+ redisKey,
3739 HOST_ID ,
3840 METRIC_HOST_NAME
3941 }
@@ -47,7 +49,7 @@ test('ioredis instrumentation', async (t) => {
4749 } )
4850
4951 await t . test ( 'creates expected metrics' , async ( t ) => {
50- const { agent, redisClient, HOST_ID } = t . nr
52+ const { agent, redisClient, redisKey , HOST_ID } = t . nr
5153 const plan = tspl ( t , { plan : 6 } )
5254 agent . on ( 'transactionFinished' , function ( tx ) {
5355 const expected = [
@@ -61,15 +63,15 @@ test('ioredis instrumentation', async (t) => {
6163 } )
6264
6365 helper . runInTransaction ( agent , async ( transaction ) => {
64- await redisClient . set ( 'testkey' , 'testvalue' )
66+ await redisClient . set ( redisKey , 'testvalue' )
6567 transaction . end ( )
6668 } )
6769
6870 await plan . completed
6971 } )
7072
7173 await t . test ( 'creates expected segments' , async ( t ) => {
72- const { agent, redisClient } = t . nr
74+ const { agent, redisClient, redisKey } = t . nr
7375 const plan = tspl ( t , { plan : 5 } )
7476
7577 agent . on ( 'transactionFinished' , function ( tx ) {
@@ -89,20 +91,19 @@ test('ioredis instrumentation', async (t) => {
8991 } )
9092
9193 helper . runInTransaction ( agent , async ( transaction ) => {
92- await redisClient . set ( 'testkey' , 'testvalue' )
93- const value = await redisClient . get ( 'testkey' )
94- plan . equal ( value , 'testvalue' , 'should have expected value' )
94+ await redisClient . set ( redisKey , 'testvalue' )
95+ const value = await redisClient . get ( redisKey )
96+ plan . equal ( value , 'testvalue' )
9597 transaction . end ( )
9698 } )
9799 await plan . completed
98100 } )
99101
100102 await t . test ( 'should add instance attributes to all redis segments' , async ( t ) => {
101- const { agent, redisClient, METRIC_HOST_NAME } = t . nr
103+ const { agent, redisClient, redisKey , METRIC_HOST_NAME } = t . nr
102104 agent . config . datastore_tracer . instance_reporting . enabled = true
103105 agent . config . datastore_tracer . database_name_reporting . enabled = true
104106 const plan = tspl ( t , { plan : 12 } )
105-
106107 agent . on ( 'transactionFinished' , function ( tx ) {
107108 const root = tx . trace . root
108109 const children = tx . trace . getChildren ( root . id )
@@ -113,27 +114,27 @@ test('ioredis instrumentation', async (t) => {
113114 const getAttrs = getSegment . getAttributes ( )
114115 plan . equal ( setAttrs . host , METRIC_HOST_NAME )
115116 plan . equal ( setAttrs . product , 'Redis' )
116- plan . equal ( setAttrs . key , '"testkey"' )
117+ plan . equal ( setAttrs . key , `" ${ redisKey } "` )
117118 plan . equal ( setAttrs . port_path_or_id , params . redis_port . toString ( ) )
118119 plan . equal ( setAttrs . database_name , String ( DB_INDEX ) )
119120 plan . equal ( getAttrs . host , METRIC_HOST_NAME )
120121 plan . equal ( getAttrs . product , 'Redis' )
121- plan . equal ( getAttrs . key , '"testkey"' )
122+ plan . equal ( getAttrs . key , `" ${ redisKey } "` )
122123 plan . equal ( getAttrs . port_path_or_id , params . redis_port . toString ( ) )
123124 plan . equal ( getAttrs . database_name , String ( DB_INDEX ) )
124125 } )
125126
126127 helper . runInTransaction ( agent , async ( transaction ) => {
127- await redisClient . set ( 'testkey' , 'testvalue' )
128- const value = await redisClient . get ( 'testkey' )
129- plan . equal ( value , 'testvalue' , 'should have expected value' )
128+ await redisClient . set ( redisKey , 'testvalue' )
129+ const value = await redisClient . get ( redisKey )
130+ plan . equal ( value , 'testvalue' )
130131 transaction . end ( )
131132 } )
132133 await plan . completed
133134 } )
134135
135136 await t . test ( 'should not add instance attributes to redis segments when disabled' , async ( t ) => {
136- const { agent, redisClient, HOST_ID } = t . nr
137+ const { agent, redisClient, redisKey , HOST_ID } = t . nr
137138 const plan = tspl ( t , { plan : 13 } )
138139 agent . config . datastore_tracer . instance_reporting . enabled = false
139140 agent . config . datastore_tracer . database_name_reporting . enabled = false
@@ -148,29 +149,29 @@ test('ioredis instrumentation', async (t) => {
148149 const getAttrs = getSegment . getAttributes ( )
149150 plan . equal ( setAttrs . host , undefined )
150151 plan . equal ( setAttrs . product , 'Redis' )
151- plan . equal ( setAttrs . key , '"testkey"' )
152+ plan . equal ( setAttrs . key , `" ${ redisKey } "` )
152153 plan . equal ( setAttrs . port_path_or_id , undefined )
153154 plan . equal ( setAttrs . database_name , undefined )
154155 plan . equal ( getAttrs . host , undefined )
155156 plan . equal ( getAttrs . product , 'Redis' )
156- plan . equal ( getAttrs . key , '"testkey"' )
157+ plan . equal ( getAttrs . key , `" ${ redisKey } "` )
157158 plan . equal ( getAttrs . port_path_or_id , undefined )
158159 plan . equal ( getAttrs . database_name , undefined )
159160 const unscoped = tx . metrics . unscoped
160161 plan . equal ( unscoped [ `Datastore/instance/Redis/${ HOST_ID } ` ] , undefined )
161162 } )
162163
163164 helper . runInTransaction ( agent , async ( transaction ) => {
164- await redisClient . set ( 'testkey' , 'testvalue' )
165- const value = await redisClient . get ( 'testkey' )
166- plan . equal ( value , 'testvalue' , 'should have expected value' )
165+ await redisClient . set ( redisKey , 'testvalue' )
166+ const value = await redisClient . get ( redisKey )
167+ plan . equal ( value , 'testvalue' )
167168 transaction . end ( )
168169 } )
169170 await plan . completed
170171 } )
171172
172173 await t . test ( 'should follow selected database' , async ( t ) => {
173- const { agent, redisClient } = t . nr
174+ const { agent, redisClient, redisKey } = t . nr
174175 const plan = tspl ( t , { plan : 7 } )
175176 const SELECTED_DB = 8
176177
@@ -189,20 +190,20 @@ test('ioredis instrumentation', async (t) => {
189190 } )
190191
191192 helper . runInTransaction ( agent , async ( transaction ) => {
192- await redisClient . set ( 'testkey' , 'testvalue' )
193+ await redisClient . set ( redisKey , 'testvalue' )
193194 await redisClient . select ( SELECTED_DB )
194- await redisClient . set ( 'testkey2' , 'testvalue' )
195+ await redisClient . set ( ` ${ redisKey } 2` , 'testvalue' )
195196 transaction . end ( )
196197 } )
197198 await plan . completed
198199 } )
199200
200201 // NODE-1524 regression
201202 await t . test ( 'does not crash when ending out of transaction' , ( t , end ) => {
202- const { agent, redisClient } = t . nr
203+ const { agent, redisClient, redisKey } = t . nr
203204 helper . runInTransaction ( agent , ( transaction ) => {
204205 assert . ok ( agent . getTransaction ( ) , 'transaction should be in progress' )
205- redisClient . set ( 'testkey' , 'testvalue' ) . then ( function ( ) {
206+ redisClient . set ( redisKey , 'testvalue' ) . then ( function ( ) {
206207 assert . ok ( ! agent . getTransaction ( ) , 'transaction should have ended' )
207208 end ( )
208209 } )
0 commit comments