Skip to content

Commit f375ea7

Browse files
authored
Merge pull request clue#64 from clue-labs/busy
Remove underdocumented isBusy() method
2 parents aa41eb9 + bf1c4a6 commit f375ea7

File tree

4 files changed

+22
-54
lines changed

4 files changed

+22
-54
lines changed

src/Client.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ interface Client extends EventEmitterInterface
3333
*/
3434
public function __call($name, $args);
3535

36-
/**
37-
* Checks if the client is busy, i.e. still has any requests pending
38-
*
39-
* @return boolean
40-
*/
41-
public function isBusy();
42-
4336
/**
4437
* end connection once all pending requests have been replied to
4538
*

src/StreamingClient.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,16 @@ public function handleMessage(ModelInterface $message)
143143
$request->resolve($message->getValueNative());
144144
}
145145

146-
if ($this->ending && !$this->isBusy()) {
146+
if ($this->ending && !$this->requests) {
147147
$this->close();
148148
}
149149
}
150150

151-
public function isBusy()
152-
{
153-
return !!$this->requests;
154-
}
155-
156151
public function end()
157152
{
158153
$this->ending = true;
159154

160-
if (!$this->isBusy()) {
155+
if (!$this->requests) {
161156
$this->close();
162157
}
163158
}

tests/FunctionalTest.php

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ public function testPing()
3030

3131
$promise = $client->ping();
3232
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
33-
$promise->then($this->expectCallableOnce('PONG'));
3433

35-
$this->assertTrue($client->isBusy());
36-
$this->waitFor($client);
37-
$this->assertFalse($client->isBusy());
34+
$ret = Block\await($promise, $this->loop);
35+
36+
$this->assertEquals('PONG', $ret);
3837

3938
return $client;
4039
}
@@ -45,10 +44,10 @@ public function testMgetIsNotInterpretedAsSubMessage()
4544

4645
$client->mset('message', 'message', 'channel', 'channel', 'payload', 'payload');
4746

48-
$client->mget('message', 'channel', 'payload')->then($this->expectCallableOnce());
47+
$promise = $client->mget('message', 'channel', 'payload')->then($this->expectCallableOnce());
4948
$client->on('message', $this->expectCallableNever());
5049

51-
$this->waitFor($client);
50+
Block\await($promise, $this->loop);
5251
}
5352

5453
public function testPipeline()
@@ -58,26 +57,25 @@ public function testPipeline()
5857
$client->set('a', 1)->then($this->expectCallableOnce('OK'));
5958
$client->incr('a')->then($this->expectCallableOnce(2));
6059
$client->incr('a')->then($this->expectCallableOnce(3));
61-
$client->get('a')->then($this->expectCallableOnce('3'));
62-
63-
$this->assertTrue($client->isBusy());
60+
$promise = $client->get('a')->then($this->expectCallableOnce('3'));
6461

65-
$this->waitFor($client);
62+
Block\await($promise, $this->loop);
6663
}
6764

6865
public function testInvalidCommand()
6966
{
70-
$this->client->doesnotexist(1, 2, 3)->then($this->expectCallableNever());
67+
$promise = $this->client->doesnotexist(1, 2, 3);
7168

72-
$this->waitFor($this->client);
69+
$this->setExpectedException('Exception');
70+
Block\await($promise, $this->loop);
7371
}
7472

7573
public function testMultiExecEmpty()
7674
{
7775
$this->client->multi()->then($this->expectCallableOnce('OK'));
78-
$this->client->exec()->then($this->expectCallableOnce(array()));
76+
$promise = $this->client->exec()->then($this->expectCallableOnce(array()));
7977

80-
$this->waitFor($this->client);
78+
Block\await($promise, $this->loop);
8179
}
8280

8381
public function testMultiExecQueuedExecHasValues()
@@ -89,9 +87,9 @@ public function testMultiExecQueuedExecHasValues()
8987
$client->expire('b', 20)->then($this->expectCallableOnce('QUEUED'));
9088
$client->incrBy('b', 2)->then($this->expectCallableOnce('QUEUED'));
9189
$client->ttl('b')->then($this->expectCallableOnce('QUEUED'));
92-
$client->exec()->then($this->expectCallableOnce(array('OK', 1, 12, 20)));
90+
$promise = $client->exec()->then($this->expectCallableOnce(array('OK', 1, 12, 20)));
9391

94-
$this->waitFor($client);
92+
Block\await($promise, $this->loop);
9593
}
9694

9795
public function testPubSub()
@@ -106,11 +104,9 @@ public function testPubSub()
106104
$consumer->on('message', $this->expectCallableOnce());
107105
$consumer->on('message', array($deferred, 'resolve'));
108106
$consumer->subscribe($channel)->then($this->expectCallableOnce());
109-
$this->waitFor($consumer);
110107

111108
// producer sends a single message
112-
$producer->publish($channel, 'hello world')->then($this->expectCallableOnce());
113-
$this->waitFor($producer);
109+
$producer->publish($channel, 'hello world')->then($this->expectCallableOnce(1));
114110

115111
// expect "message" event to take no longer than 0.1s
116112
Block\await($deferred->promise(), $this->loop, 0.1);
@@ -132,9 +128,10 @@ public function testInvalidProtocol()
132128
$client->on('error', $this->expectCallableOnce());
133129
$client->on('close', $this->expectCallableOnce());
134130

135-
$client->get('willBeRejectedDueToClosing')->then(null, $this->expectCallableOnce());
131+
$promise = $client->get('willBeRejectedDueToClosing');
136132

137-
$this->waitFor($client);
133+
$this->setExpectedException('Exception');
134+
Block\await($promise, $this->loop);
138135
}
139136

140137
public function testInvalidServerRepliesWithDuplicateMessages()
@@ -144,9 +141,9 @@ public function testInvalidServerRepliesWithDuplicateMessages()
144141
$client->on('error', $this->expectCallableOnce());
145142
$client->on('close', $this->expectCallableOnce());
146143

147-
$client->set('a', 0)->then($this->expectCallableOnce('OK'));
144+
$promise = $client->set('a', 0)->then($this->expectCallableOnce('OK'));
148145

149-
$this->waitFor($client);
146+
Block\await($promise, $this->loop);
150147
}
151148

152149
/**
@@ -175,13 +172,4 @@ protected function createServer($response)
175172
$cmd = 'echo -e "' . str_replace("\r\n", '\r\n', $response) . '" | nc -lC ' . $port;
176173

177174
}
178-
179-
protected function waitFor(StreamingClient $client)
180-
{
181-
$this->assertTrue($client->isBusy());
182-
183-
while ($client->isBusy()) {
184-
$this->loop->tick();
185-
}
186-
}
187175
}

tests/StreamingClientTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public function testMonitorCommandIsNotSupported()
8585
$promise = $this->client->monitor();
8686

8787
$this->expectPromiseReject($promise);
88-
$this->assertFalse($this->client->isBusy());
8988
}
9089

9190

@@ -103,28 +102,21 @@ public function testErrorReply()
103102
public function testClosingClientRejectsAllRemainingRequests()
104103
{
105104
$promise = $this->client->ping();
106-
$this->assertTrue($this->client->isBusy());
107-
108105
$this->client->close();
109106

110107
$this->expectPromiseReject($promise);
111-
$this->assertFalse($this->client->isBusy());
112108
}
113109

114110
public function testClosedClientRejectsAllNewRequests()
115111
{
116112
$this->client->close();
117-
118113
$promise = $this->client->ping();
119114

120115
$this->expectPromiseReject($promise);
121-
$this->assertFalse($this->client->isBusy());
122116
}
123117

124118
public function testEndingNonBusyClosesClient()
125119
{
126-
$this->assertFalse($this->client->isBusy());
127-
128120
$this->client->on('close', $this->expectCallableOnce());
129121
$this->client->end();
130122
}

0 commit comments

Comments
 (0)