Skip to content

Commit 5d508ca

Browse files
authored
Merge pull request #61 from tidal/develop
maintenance
2 parents 246c84d + cf38ca7 commit 5d508ca

File tree

6 files changed

+57
-13
lines changed

6 files changed

+57
-13
lines changed

examples/crossbar_session/monitor.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
);
3030

3131
$connection->on('open', function (ClientSession $session) use ($connection, &$timer) {
32-
$sessionMonitor = new SessionMonitor(new Adapter($session, new PromiseFactory()));
32+
$sessionMonitor = SessionMonitor::create(new Adapter($session, new PromiseFactory()));
3333

3434
echo PHP_EOL . "******** SESSION MONITOR STARTED ********" . PHP_EOL;
3535
$sessionMonitor->on('start', function ($l) {
@@ -42,12 +42,23 @@
4242
print_r($l);
4343
});
4444

45-
$sessionMonitor->on('join', function ($sessionData) {
45+
$sessionMonitor->on('join', function ($sessionData) use ($sessionMonitor) {
4646
echo PHP_EOL . "JOIN: {$sessionData->session}" . PHP_EOL;
47+
48+
$sessionMonitor->getSessionIds()->then(function (array $sessions) {
49+
50+
echo "SESSIONS : " . count($sessions) . PHP_EOL;
51+
52+
});
4753
});
4854

49-
$sessionMonitor->on('leave', function ($sessionId) {
55+
$sessionMonitor->on('leave', function ($sessionId) use ($sessionMonitor) {
5056
echo PHP_EOL . "LEAVE: $sessionId" . PHP_EOL;
57+
$sessionMonitor->getSessionIds()->then(function (array $sessions) {
58+
59+
echo "SESSIONS : " . count($sessions) . PHP_EOL;
60+
61+
});
5162
});
5263

5364
$sessionMonitor->on('error', function ($l) {

examples/thruway_internal_session_monitor/InternalSessionMonitor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public function onSessionStart($session, $transport)
5151
print_r($l);
5252
});
5353

54-
$sessionMonitor->on('error', function ($l) {
55-
echo PHP_EOL . "ERROR: " . PHP_EOL;
56-
print_r($l);
54+
$sessionMonitor->on('error', function ($l, $i = 'default') {
55+
echo PHP_EOL . "ERROR REQUEST $i : " . PHP_EOL;
56+
print_r(func_get_args());
5757
});
5858

5959
$sessionMonitor->start();

src/Tidal/WampWatch/SessionMonitor.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
namespace Tidal\WampWatch;
1313

1414
use Evenement\EventEmitterInterface;
15+
use Thruway\Message\ErrorMessage;
1516
use Tidal\WampWatch\ClientSessionInterface as ClientSession;
1617
use Tidal\WampWatch\Adapter\React\PromiseAdapter;
18+
use Tidal\WampWatch\Async\PromiseInterface;
1719

1820
/**
1921
* Description of SessionMonitor.
@@ -62,7 +64,7 @@ public function __construct(ClientSession $session)
6264
*
6365
* @param $sessionId
6466
*
65-
* @return PromiseAdapter
67+
* @return PromiseInterface
6668
*/
6769
public function getSessionInfo($sessionId)
6870
{
@@ -72,8 +74,8 @@ function ($res) {
7274

7375
return $res;
7476
},
75-
function ($error) {
76-
$this->emit('error', [$error]);
77+
function (ErrorMessage $error) use ($sessionId) {
78+
$this->emit('error', [$error, $sessionId]);
7779
}
7880
);
7981
}
@@ -250,4 +252,9 @@ protected function removeOwnSessionId(array $sessionsIds)
250252

251253
return $sessionsIds;
252254
}
255+
256+
public static function create(ClientSession $session)
257+
{
258+
return new self($session);
259+
}
253260
}

tests/integration/crossbar/CrosssbarSessionMonitorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function test_onstart()
4444

4545
$this->connection->open();
4646

47+
// wait for connection to be established
48+
sleep(1);
49+
4750
$this->assertTrue(is_array($sessionIds));
4851
}
4952

@@ -79,6 +82,9 @@ public function test_onjoin()
7982

8083
$this->connection->open();
8184

85+
// wait for connection to be established
86+
sleep(1);
87+
8288
$this->assertEquals($this->clientSessionId, $this->monitoredSessionId);
8389
}
8490

@@ -114,6 +120,9 @@ public function test_onleave()
114120

115121
$this->connection->open();
116122

123+
// wait for connection to be established
124+
sleep(1);
125+
117126
$this->assertEquals($this->clientSessionId, $this->monitoredSessionId);
118127
}
119128
}

tests/integration/crossbar/CrosssbarSubscriptionMonitorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public function test_onstart()
7575

7676
$this->connection->open();
7777

78+
// wait for connection to be established
79+
sleep(1);
80+
7881
$this->validateSubscriptionInfo($this->initialSubscriptionInfo);
7982
}
8083

@@ -101,6 +104,9 @@ public function test_onstart_delivers_current_list()
101104

102105
$clientConnection->open();
103106

107+
// wait for connection to be established
108+
sleep(1);
109+
104110
$this->validateSubscriptionInfo($this->initialSubscriptionInfo);
105111
$this->assertArraySubset([$subscriptionId], $this->initialSubscriptionInfo->exact);
106112
}
@@ -131,6 +137,9 @@ public function test_oncreate()
131137

132138
$this->getConnection()->open();
133139

140+
// wait for connection to be established
141+
sleep(1);
142+
134143
$this->assertInternalType('int', $this->creatorSessionId);
135144
$this->assertInstanceOf(\stdClass::class, $this->clientSubscriptionInfo);
136145
$this->assertAttributeEquals($this->testTopicName, 'uri', $this->clientSubscriptionInfo);
@@ -207,6 +216,9 @@ public function test_onunsubscribe()
207216

208217
$this->connection->open();
209218

219+
// wait for connection to be established
220+
sleep(1);
221+
210222
$this->assertInternalType('int', $sessionId);
211223
$this->assertInternalType('int', $subscriptionId);
212224
}
@@ -256,6 +268,9 @@ public function test_ondelete()
256268

257269
$this->connection->open();
258270

271+
// wait for connection to be established
272+
sleep(1);
273+
259274
$this->assertInternalType('int', $sessionId);
260275
$this->assertInternalType('int', $subscriptionId);
261276
}

tests/unit/SessionMonitorTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Tidal\WampWatch\Stub\ClientSessionStub;
1818
use PHPUnit_Framework_TestCase;
1919
use stdClass;
20+
use Thruway\Message;
2021

2122
/**
2223
* @author Timo Michna <[email protected]>
@@ -401,12 +402,13 @@ public function test_get_sessioninfo_fail_emits_event()
401402

402403
$monitor->getSessionInfo(654);
403404

404-
$sessionInfo = new stdClass();
405-
$sessionInfo->session = 654;
405+
$errorMessage = $this->getMockBuilder(Message\ErrorMessage::class)
406+
->disableOriginalConstructor()
407+
->getMock();
406408

407-
$stub->failCall(SessionMonitor::SESSION_INFO_TOPIC, $sessionInfo);
409+
$stub->failCall(SessionMonitor::SESSION_INFO_TOPIC, $errorMessage);
408410

409-
$this->assertSame($sessionInfo, $response);
411+
$this->assertSame($errorMessage, $response);
410412
}
411413

412414
public function test_invalid_sessioninfo_does_not_get_added()

0 commit comments

Comments
 (0)