Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/ssh/__tests__/DiffusionMercurialWireSSHTestCase.php
12242 views
1
<?php
2
3
final class DiffusionMercurialWireSSHTestCase extends PhabricatorTestCase {
4
5
public function testMercurialClientWireProtocolParser() {
6
$data = dirname(__FILE__).'/hgwiredata/';
7
$dir = Filesystem::listDirectory($data, $include_hidden = false);
8
foreach ($dir as $file) {
9
$raw = Filesystem::readFile($data.$file);
10
$raw = explode("\n~~~~~~~~~~\n", $raw, 2);
11
$this->assertEqual(2, count($raw));
12
$expect = phutil_json_decode($raw[1]);
13
$this->assertTrue(is_array($expect), $file);
14
15
$this->assertParserResult($expect, $raw[0], $file);
16
}
17
}
18
19
private function assertParserResult(array $expect, $input, $file) {
20
list($x, $y) = PhutilSocketChannel::newChannelPair();
21
$xp = new DiffusionMercurialWireClientSSHProtocolChannel($x);
22
23
$y->write($input);
24
$y->flush();
25
$y->closeWriteChannel();
26
27
$messages = array();
28
for ($ii = 0; $ii < count($expect); $ii++) {
29
try {
30
$messages[] = $xp->waitForMessage();
31
} catch (Exception $ex) {
32
// This is probably the parser not producing as many messages as
33
// we expect. Log the exception, but continue to the assertion below
34
// since that will often be easier to diagnose.
35
phlog($ex);
36
break;
37
}
38
}
39
40
$this->assertEqual($expect, $messages, $file);
41
42
// Now, make sure the channel doesn't have *more* messages than we expect.
43
// Specifically, it should throw when we try to read another message.
44
$caught = null;
45
try {
46
$xp->waitForMessage();
47
} catch (Exception $ex) {
48
$caught = $ex;
49
}
50
51
$this->assertTrue(
52
($caught instanceof Exception),
53
pht("No extra messages for '%s'.", $file));
54
}
55
56
}
57
58