Skip to content

Commit

Permalink
add pool tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianconcept committed Feb 4, 2024
1 parent 9a1651b commit f315f75
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
60 changes: 60 additions & 0 deletions src/Mapless-Redis-Tests/MaplessRedisPoolTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Class {
#name : #MaplessRedisPoolTest,
#superclass : #MaplessTestCase,
#category : #'Mapless-Redis-Tests'
}

{ #category : #tests }
MaplessRedisPoolTest >> testNewClient [

| pool |
pool := MaplessRedisPool local.

self assert: pool notNil.
self assert: pool redis notNil.
self assert: pool redis stick notNil.
self assert: pool redis stick targetUrl notNil.
self assert: pool redis stick targetUrl equals: 'sync://localhost'.

pool := MaplessRedisPool targetUrl: 'sync://127.0.0.1'.
self assert: pool redis stick targetUrl equals: 'sync://127.0.0.1'
]

{ #category : #tests }
MaplessRedisPoolTest >> testSubscribe [

| pool valued reaction |
pool := MaplessRedisPool local.
valued := false.
reaction := [ :msg | msg payload ifNotNil: [ valued := true ] ].
self
shouldnt: [ pool subscribe: #testing callback: reaction ]
raise: Error.
self deny: valued.
pool publish: #testing message: 'answer'.
30 milliSeconds asDelay wait.
self assert: valued
]

{ #category : #tests }
MaplessRedisPoolTest >> testUnsubscribe [

| pool valued reaction |
pool := MaplessRedisPool local.
valued := false.
reaction := [ :msg | msg payload ifNotNil: [ valued := true ] ].
self
shouldnt: [ pool subscribe: #testing callback: reaction ]
raise: Error.
self deny: valued.
pool publish: #testing message: 'answer'.
30 milliSeconds asDelay wait.
self assert: valued.
valued := false.

pool unsubscribe: #testing.
pool publish: #testing message: 'answer'.
30 milliSeconds asDelay wait.
self deny: valued.

]
13 changes: 10 additions & 3 deletions src/Mapless-Redis/MaplessRedisPool.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ Class {

{ #category : #'instance creation' }
MaplessRedisPool class >> local [

^ self targetUrl: 'sync://localhost'
]

{ #category : #'instance creation' }
MaplessRedisPool class >> targetUrl: anUrl [

| rediStick |
rediStick := RsRediStick targetUrl: 'sync://localhost'.
rediStick := RsRediStick targetUrl: anUrl.
rediStick connect.
^ self new
redis: (RsRedis on: rediStick);
yourself
redis: (RsRedis on: rediStick);
yourself
]

{ #category : #'redis-commands' }
Expand Down

0 comments on commit f315f75

Please sign in to comment.