3
3
namespace Clue \Tests \React \Redis ;
4
4
5
5
use Clue \React \Redis \RedisClient ;
6
- use React \EventLoop \StreamSelectLoop ;
6
+ use React \EventLoop \Loop ;
7
7
use React \Promise \Deferred ;
8
8
use React \Promise \PromiseInterface ;
9
9
use function Clue \React \Block \await ;
10
+ use function React \Promise \Timer \timeout ;
10
11
11
12
class FunctionalTest extends TestCase
12
13
{
13
- /** @var StreamSelectLoop */
14
- private $ loop ;
15
14
16
15
/** @var string */
17
16
private $ uri ;
@@ -22,30 +21,28 @@ public function setUp(): void
22
21
if ($ this ->uri === '' ) {
23
22
$ this ->markTestSkipped ('No REDIS_URI environment variable given ' );
24
23
}
25
-
26
- $ this ->loop = new StreamSelectLoop ();
27
24
}
28
25
29
26
public function testPing (): void
30
27
{
31
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
28
+ $ redis = new RedisClient ($ this ->uri );
32
29
33
30
$ promise = $ redis ->ping ();
34
31
$ this ->assertInstanceOf (PromiseInterface::class, $ promise );
35
32
36
- $ ret = await ($ promise, $ this -> loop );
33
+ $ ret = await ($ promise );
37
34
38
35
$ this ->assertEquals ('PONG ' , $ ret );
39
36
}
40
37
41
38
public function testPingLazy (): void
42
39
{
43
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
40
+ $ redis = new RedisClient ($ this ->uri );
44
41
45
42
$ promise = $ redis ->ping ();
46
43
$ this ->assertInstanceOf (PromiseInterface::class, $ promise );
47
44
48
- $ ret = await ($ promise, $ this -> loop );
45
+ $ ret = await ($ promise );
49
46
50
47
$ this ->assertEquals ('PONG ' , $ ret );
51
48
}
@@ -55,70 +52,70 @@ public function testPingLazy(): void
55
52
*/
56
53
public function testPingLazyWillNotBlockLoop (): void
57
54
{
58
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
55
+ $ redis = new RedisClient ($ this ->uri );
59
56
60
57
$ redis ->ping ();
61
58
62
- $ this -> loop -> run ();
59
+ Loop:: run ();
63
60
}
64
61
65
62
/**
66
63
* @doesNotPerformAssertions
67
64
*/
68
65
public function testLazyClientWithoutCommandsWillNotBlockLoop (): void
69
66
{
70
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
67
+ $ redis = new RedisClient ($ this ->uri );
71
68
72
- $ this -> loop -> run ();
69
+ Loop:: run ();
73
70
74
71
unset($ redis );
75
72
}
76
73
77
74
public function testMgetIsNotInterpretedAsSubMessage (): void
78
75
{
79
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
76
+ $ redis = new RedisClient ($ this ->uri );
80
77
81
78
$ redis ->mset ('message ' , 'message ' , 'channel ' , 'channel ' , 'payload ' , 'payload ' );
82
79
83
80
$ promise = $ redis ->mget ('message ' , 'channel ' , 'payload ' )->then ($ this ->expectCallableOnce ());
84
81
$ redis ->on ('message ' , $ this ->expectCallableNever ());
85
82
86
- await ($ promise, $ this -> loop );
83
+ await ($ promise );
87
84
}
88
85
89
86
public function testPipeline (): void
90
87
{
91
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
88
+ $ redis = new RedisClient ($ this ->uri );
92
89
93
90
$ redis ->set ('a ' , 1 )->then ($ this ->expectCallableOnceWith ('OK ' ));
94
91
$ redis ->incr ('a ' )->then ($ this ->expectCallableOnceWith (2 ));
95
92
$ redis ->incr ('a ' )->then ($ this ->expectCallableOnceWith (3 ));
96
93
$ promise = $ redis ->get ('a ' )->then ($ this ->expectCallableOnceWith ('3 ' ));
97
94
98
- await ($ promise, $ this -> loop );
95
+ await ($ promise );
99
96
}
100
97
101
98
public function testInvalidCommand (): void
102
99
{
103
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
100
+ $ redis = new RedisClient ($ this ->uri );
104
101
$ promise = $ redis ->doesnotexist (1 , 2 , 3 );
105
102
106
103
$ this ->expectException (\Exception::class);
107
- await ($ promise, $ this -> loop );
104
+ await ($ promise );
108
105
}
109
106
110
107
public function testMultiExecEmpty (): void
111
108
{
112
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
109
+ $ redis = new RedisClient ($ this ->uri );
113
110
$ redis ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
114
111
$ promise = $ redis ->exec ()->then ($ this ->expectCallableOnceWith ([]));
115
112
116
- await ($ promise, $ this -> loop );
113
+ await ($ promise );
117
114
}
118
115
119
116
public function testMultiExecQueuedExecHasValues (): void
120
117
{
121
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
118
+ $ redis = new RedisClient ($ this ->uri );
122
119
123
120
$ redis ->multi ()->then ($ this ->expectCallableOnceWith ('OK ' ));
124
121
$ redis ->set ('b ' , 10 )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
@@ -127,13 +124,13 @@ public function testMultiExecQueuedExecHasValues(): void
127
124
$ redis ->ttl ('b ' )->then ($ this ->expectCallableOnceWith ('QUEUED ' ));
128
125
$ promise = $ redis ->exec ()->then ($ this ->expectCallableOnceWith (['OK ' , 1 , 12 , 20 ]));
129
126
130
- await ($ promise, $ this -> loop );
127
+ await ($ promise );
131
128
}
132
129
133
130
public function testPubSub (): void
134
131
{
135
- $ consumer = new RedisClient ($ this ->uri , null , $ this -> loop );
136
- $ producer = new RedisClient ($ this ->uri , null , $ this -> loop );
132
+ $ consumer = new RedisClient ($ this ->uri );
133
+ $ producer = new RedisClient ($ this ->uri );
137
134
138
135
$ channel = 'channel:test: ' . mt_rand ();
139
136
@@ -148,12 +145,15 @@ public function testPubSub(): void
148
145
})->then ($ this ->expectCallableOnce ());
149
146
150
147
// expect "message" event to take no longer than 0.1s
151
- await ($ deferred ->promise (), $ this ->loop , 0.1 );
148
+
149
+ await (timeout ($ deferred ->promise (), 0.1 ));
150
+
151
+ await ($ consumer ->unsubscribe ($ channel ));
152
152
}
153
153
154
154
public function testClose (): void
155
155
{
156
- $ redis = new RedisClient ($ this ->uri , null , $ this -> loop );
156
+ $ redis = new RedisClient ($ this ->uri );
157
157
158
158
$ redis ->get ('willBeCanceledAnyway ' )->then (null , $ this ->expectCallableOnce ());
159
159
0 commit comments