Path: blob/master/src/applications/diffusion/ssh/__tests__/DiffusionMercurialWireSSHTestCase.php
12242 views
<?php12final class DiffusionMercurialWireSSHTestCase extends PhabricatorTestCase {34public function testMercurialClientWireProtocolParser() {5$data = dirname(__FILE__).'/hgwiredata/';6$dir = Filesystem::listDirectory($data, $include_hidden = false);7foreach ($dir as $file) {8$raw = Filesystem::readFile($data.$file);9$raw = explode("\n~~~~~~~~~~\n", $raw, 2);10$this->assertEqual(2, count($raw));11$expect = phutil_json_decode($raw[1]);12$this->assertTrue(is_array($expect), $file);1314$this->assertParserResult($expect, $raw[0], $file);15}16}1718private function assertParserResult(array $expect, $input, $file) {19list($x, $y) = PhutilSocketChannel::newChannelPair();20$xp = new DiffusionMercurialWireClientSSHProtocolChannel($x);2122$y->write($input);23$y->flush();24$y->closeWriteChannel();2526$messages = array();27for ($ii = 0; $ii < count($expect); $ii++) {28try {29$messages[] = $xp->waitForMessage();30} catch (Exception $ex) {31// This is probably the parser not producing as many messages as32// we expect. Log the exception, but continue to the assertion below33// since that will often be easier to diagnose.34phlog($ex);35break;36}37}3839$this->assertEqual($expect, $messages, $file);4041// Now, make sure the channel doesn't have *more* messages than we expect.42// Specifically, it should throw when we try to read another message.43$caught = null;44try {45$xp->waitForMessage();46} catch (Exception $ex) {47$caught = $ex;48}4950$this->assertTrue(51($caught instanceof Exception),52pht("No extra messages for '%s'.", $file));53}5455}565758