indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers.
REVISION SUMMARY "readavailable" is useful as a debugging device to see what data is available on a pipe. But the mechanism isn't deterministic because what's available on a pipe is highly conditional on timing, system load, OS behavior, etc. This makes it not suitable for tests. We introduce "ereadline," "read," and "eread" for performing deterministic I/O operations (at least on blocking file descriptors). We convert uses of "readavailable" in tests to use the new primitives. This should hopefully make these tests deterministic. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2720 AFFECTED FILES mercurial/debugcommands.py tests/test-ssh-proto-unbundle.t tests/test-ssh-proto.t CHANGE DETAILS diff --git a/tests/test-ssh-proto.t b/tests/test-ssh-proto.t --- a/tests/test-ssh-proto.t +++ b/tests/test-ssh-proto.t @@ -1118,7 +1118,8 @@ > upgrade another-token proto=irrelevant\n > hello\n > readline - > readavailable + > ereadline + > ereadline > EOF using raw connection to peer i> write(153) -> 153: @@ -1138,8 +1139,9 @@ i> hello\n o> readline() -> 1: o> \n - e> read(-1) -> 42: + e> readline() -> 40: e> cannot upgrade protocols multiple times\n + e> readline() -> 2: e> -\n Malformed upgrade request line (not exactly 3 space delimited tokens) @@ -1221,35 +1223,39 @@ > upgrade token proto=exp-ssh-v2-0001\n > invalid\n > readline - > readavailable + > ereadline + > ereadline > EOF using raw connection to peer i> write(44) -> 44: i> upgrade token proto=exp-ssh-v2-0001\n i> invalid\n o> readline() -> 1: o> \n - e> read(-1) -> 46: + e> readline() -> 44: e> malformed handshake protocol: missing hello\n + e> readline() -> 2: e> -\n $ hg debugwireproto --localssh --peer raw << EOF > raw > upgrade token proto=exp-ssh-v2-0001\n > hello\n > invalid\n > readline - > readavailable + > ereadline + > ereadline > EOF using raw connection to peer i> write(50) -> 50: i> upgrade token proto=exp-ssh-v2-0001\n i> hello\n i> invalid\n o> readline() -> 1: o> \n - e> read(-1) -> 48: + e> readline() -> 46: e> malformed handshake protocol: missing between\n + e> readline() -> 2: e> -\n $ hg debugwireproto --localssh --peer raw << EOF @@ -1259,7 +1265,8 @@ > between\n > invalid\n > readline - > readavailable + > ereadline + > ereadline > EOF using raw connection to peer i> write(58) -> 58: @@ -1269,8 +1276,9 @@ i> invalid\n o> readline() -> 1: o> \n - e> read(-1) -> 49: + e> readline() -> 47: e> malformed handshake protocol: missing pairs 81\n + e> readline() -> 2: e> -\n Legacy commands are not exposed to version 2 of protocol diff --git a/tests/test-ssh-proto-unbundle.t b/tests/test-ssh-proto-unbundle.t --- a/tests/test-ssh-proto-unbundle.t +++ b/tests/test-ssh-proto-unbundle.t @@ -45,7 +45,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 115 > EOF testing ssh1 creating ssh peer from handshake results @@ -93,7 +93,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 115: + e> read(115) -> 115: e> abort: incompatible Mercurial client; bundle2 required\n e> (see https://www.mercurial-scm.org/wiki/IncompatibleClient)\n @@ -143,7 +143,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 115: + e> read(115) -> 115: e> abort: incompatible Mercurial client; bundle2 required\n e> (see https://www.mercurial-scm.org/wiki/IncompatibleClient)\n @@ -212,7 +212,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 196 > EOF testing ssh1 creating ssh peer from handshake results @@ -260,7 +260,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 196: + e> read(196) -> 196: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -316,7 +316,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 196: + e> read(196) -> 196: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -338,7 +338,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 218 > EOF testing ssh1 creating ssh peer from handshake results @@ -386,7 +386,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 218: + e> read(218) -> 218: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -443,7 +443,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 218: + e> read(218) -> 218: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -466,7 +466,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 202 > EOF testing ssh1 creating ssh peer from handshake results @@ -514,7 +514,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 202: + e> read(202) -> 202: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -570,7 +570,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 202: + e> read(202) -> 202: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -592,7 +592,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 206 > EOF testing ssh1 creating ssh peer from handshake results @@ -640,7 +640,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 206: + e> read(206) -> 206: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -697,7 +697,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 206: + e> read(206) -> 206: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -720,7 +720,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 232 > EOF testing ssh1 creating ssh peer from handshake results @@ -768,7 +768,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 232: + e> read(232) -> 232: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -827,7 +827,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 232: + e> read(232) -> 232: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -852,7 +852,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 193 > EOF testing ssh1 creating ssh peer from handshake results @@ -900,7 +900,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 193: + e> read(193) -> 193: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -956,7 +956,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 193: + e> read(193) -> 193: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -978,7 +978,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 218 > EOF testing ssh1 creating ssh peer from handshake results @@ -1026,7 +1026,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 218: + e> read(218) -> 218: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1085,7 +1085,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 218: + e> read(218) -> 218: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1110,7 +1110,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 216 > EOF testing ssh1 creating ssh peer from handshake results @@ -1158,7 +1158,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 216: + e> read(216) -> 216: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1217,7 +1217,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 216: + e> read(216) -> 216: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1248,7 +1248,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 212 > EOF testing ssh1 creating ssh peer from handshake results @@ -1296,7 +1296,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 212: + e> read(212) -> 212: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1353,7 +1353,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 212: + e> read(212) -> 212: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1377,7 +1377,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 212 > EOF testing ssh1 creating ssh peer from handshake results @@ -1425,7 +1425,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 212: + e> read(212) -> 212: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1482,7 +1482,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 212: + e> read(212) -> 212: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1508,7 +1508,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 230 > EOF testing ssh1 creating ssh peer from handshake results @@ -1556,7 +1556,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 230: + e> read(230) -> 230: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1615,7 +1615,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 230: + e> read(230) -> 230: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1649,7 +1649,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 273 > EOF testing ssh1 creating ssh peer from handshake results @@ -1697,7 +1697,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 273: + e> read(273) -> 273: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1760,7 +1760,7 @@ o> read(1) -> 1: 0 result: 0 remote output: - e> read(-1) -> 273: + e> read(273) -> 273: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1789,7 +1789,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 100 > EOF testing ssh1 creating ssh peer from handshake results @@ -1837,7 +1837,7 @@ o> read(1) -> 1: 1 result: 1 remote output: - e> read(-1) -> 100: + e> read(100) -> 100: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1889,7 +1889,7 @@ o> read(1) -> 1: 1 result: 1 remote output: - e> read(-1) -> 100: + e> read(100) -> 100: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -1919,7 +1919,7 @@ > # This is "force" in hex. > heads 666f726365 > PUSHFILE ../initial.v1.hg - > readavailable + > eread 152 > EOF testing ssh1 creating ssh peer from handshake results @@ -1967,7 +1967,7 @@ o> read(1) -> 1: 1 result: 1 remote output: - e> read(-1) -> 152: + e> read(152) -> 152: e> adding changesets\n e> adding manifests\n e> adding file changes\n @@ -2023,7 +2023,7 @@ o> read(1) -> 1: 1 result: 1 remote output: - e> read(-1) -> 152: + e> read(152) -> 152: e> adding changesets\n e> adding manifests\n e> adding file changes\n diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -2683,6 +2683,21 @@ Read a line of output from the server. If there are multiple output pipes, reads only the main pipe. + + ereadline + --------- + + Like ``readline``, but read from the stderr pipe, if available. + + read <X> + -------- + + ``read()`` N bytes from the server's main output pipe. + + eread <X> + --------- + + ``read()`` N bytes from the server's stderr pipe, if available. """ opts = pycompat.byteskwargs(opts) @@ -2831,6 +2846,14 @@ util.readpipe(stderr) elif action == 'readline': stdout.readline() + elif action == 'ereadline': + stderr.readline() + elif action.startswith('read '): + count = int(action.split(' ', 1)[1]) + stdout.read(count) + elif action.startswith('eread '): + count = int(action.split(' ', 1)[1]) + stderr.read(count) else: raise error.Abort(_('unknown action: %s') % action) To: indygreg, #hg-reviewers Cc: mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel