pexpect / ptyprocess

Run a subprocess in a pseudo terminal
https://ptyprocess.readthedocs.io/en/latest/
Other
222 stars 71 forks source link

Race condition (fail) in tests.test_spawn.PtyTestCase.test_spawn_sh_unicode #25

Open jquast opened 9 years ago

jquast commented 9 years ago

The test is likely at fault. It is attempting to see its own keyboard input in output, but the prompt is displaying late, causing the familiar "input echo intermittently spanned in output" condition:

AssertionError: assert 'echo $ENV_KEY; exit 0' in 'echo $EN(teamcity-pexpect)(teamcity-pexpect)V_KEY; exit 0\r\nenv_value\r\n' 

Full output and link

self = <tests.test_spawn.PtyTestCase testMethod=test_spawn_sh_unicode>
ptyp = <class 'ptyprocess.ptyprocess.PtyProcessUnicode'>
cmd = 'echo $ENV_KEY; exit 0\n'
outp = 'echo $EN(teamcity-pexpect)(teamcity-pexpect)V_KEY; exit 0\r\nenv_value\r\n'
env_value = 'env_value'

    def _spawn_sh(self, ptyp, cmd, outp, env_value):
        # given,
        p = ptyp.spawn(['sh'], env=self.env)
        p.write(cmd)

        # exercise,
        while True:
            try:
                outp += p.read()
            except EOFError:
                break

        # verify, input is echo to output
>       assert cmd.strip() in outp
E       AssertionError: assert 'echo $ENV_KEY; exit 0' in 'echo $EN(teamcity-pexpect)(teamcity-pexpect)V_KEY; exit 0\r\nenv_value\r\n'
E        +  where 'echo $ENV_KEY; exit 0' = <built-in method strip of str object at 0x7f2231b5f540>()
E        +    where <built-in method strip of str object at 0x7f2231b5f540> = 'echo $ENV_KEY; exit 0\n'.strip

https://teamcity-master.pexpect.org/viewLog.html?buildId=13605&buildTypeId=Pexpect_LinuxBuild&tab=buildLog

takluyver commented 9 years ago

I guess we need to add some kind of wait (either sleep or check for a condition) to ensure the prompt is displayed before we send input.