1
1
import { test } from '@japa/runner'
2
2
import { setTimeout } from 'node:timers/promises'
3
- import { RedisTransport } from '@boringnode/bus/transports/redis'
4
3
import { MemoryTransport } from '@boringnode/bus/transports/memory'
5
4
6
- import { RedisDriver } from '../../src/drivers/redis.js'
7
5
import { ChaosBus } from '../helpers/chaos/chaos_bus.js'
8
6
import { ChaosCache } from '../helpers/chaos/chaos_cache.js'
9
7
import { CacheBusMessageType } from '../../src/types/bus.js'
10
8
import { CacheFactory } from '../../factories/cache_factory.js'
9
+ import { RedisDriver , redisBusDriver } from '../../src/drivers/redis.js'
11
10
import { REDIS_CREDENTIALS , throwingFactory } from '../helpers/index.js'
12
- import { BinaryEncoder } from '../../src/bus/encoders/binary_encoder.js'
13
11
14
12
test . group ( 'Bus synchronization' , ( ) => {
15
13
test ( 'synchronize multiple cache' , async ( { assert } ) => {
@@ -186,8 +184,13 @@ test.group('Bus synchronization', () => {
186
184
} )
187
185
188
186
test ( 'binary encoding/decoding should works fine' , async ( { assert, cleanup } , done ) => {
189
- const bus1 = new RedisTransport ( REDIS_CREDENTIALS , new BinaryEncoder ( ) ) . setId ( 'foo' )
190
- const bus2 = new RedisTransport ( REDIS_CREDENTIALS , new BinaryEncoder ( ) ) . setId ( 'bar' )
187
+ const bus1 = redisBusDriver ( { connection : REDIS_CREDENTIALS } )
188
+ . factory ( null as any )
189
+ . setId ( 'foo' )
190
+
191
+ const bus2 = redisBusDriver ( { connection : REDIS_CREDENTIALS } )
192
+ . factory ( null as any )
193
+ . setId ( 'bar' )
191
194
192
195
cleanup ( async ( ) => {
193
196
await bus1 . disconnect ( )
@@ -210,4 +213,34 @@ test.group('Bus synchronization', () => {
210
213
} )
211
214
. waitForDone ( )
212
215
. disableTimeout ( )
216
+
217
+ test ( 'works with utf8 characters' , async ( { assert } , done ) => {
218
+ const bus1 = redisBusDriver ( { connection : REDIS_CREDENTIALS } )
219
+ . factory ( null as any )
220
+ . setId ( 'foo' )
221
+
222
+ const bus2 = redisBusDriver ( { connection : REDIS_CREDENTIALS } )
223
+ . factory ( null as any )
224
+ . setId ( 'bar' )
225
+
226
+ const data = {
227
+ keys : [ 'foo' , '1' , '2' , 'bar' , 'key::test' , '🚀' ] ,
228
+ type : CacheBusMessageType . Set ,
229
+ }
230
+
231
+ bus1 . subscribe ( 'foo' , ( message : any ) => {
232
+ assert . deepInclude ( message , data )
233
+ done ( )
234
+ } )
235
+
236
+ await setTimeout ( 200 )
237
+
238
+ await bus2 . publish ( 'foo' , data )
239
+
240
+ await bus1 . disconnect ( )
241
+
242
+ await bus2 . disconnect ( )
243
+
244
+ await setTimeout ( 200 )
245
+ } ) . waitForDone ( )
213
246
} )
0 commit comments