3 final class DiffusionMercurialWireSSHTestCase
extends PhabricatorTestCase
{
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);
15 $this->assertParserResult($expect, $raw[0], $file);
19 private function assertParserResult(array $expect, $input, $file) {
20 list($x, $y) = PhutilSocketChannel
::newChannelPair();
21 $xp = new DiffusionMercurialWireClientSSHProtocolChannel($x);
25 $y->closeWriteChannel();
28 for ($ii = 0; $ii < count($expect); $ii++
) {
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.
40 $this->assertEqual($expect, $messages, $file);
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.
46 $xp->waitForMessage();
47 } catch (Exception
$ex) {
52 ($caught instanceof Exception
),
53 pht("No extra messages for '%s'.", $file));