Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a method "isTtySupported" for setTty method. #136

Closed
wants to merge 1 commit into from
Closed

Implement a method "isTtySupported" for setTty method. #136

wants to merge 1 commit into from

Conversation

mamor
Copy link

@mamor mamor commented Feb 19, 2017

I tried dusk with PhantomJS on Wercker. and I have same issue this.
https://laracasts.com/discuss/channels/testing/tty-mode-requires-devtty-to-be-writable

Like that comment "run as script" can be executed.
but Wercker continued build when dusk fails, probably exit code does not return.
This problem will be occored on CircleCI, GitLab CI, cron and more.

I fixed that, change to the same logic Symfony\Component\Process\Process#setTty()
https://github.com/symfony/process/blob/master/Process.php#L1036

and this is execution result.

$ cat /tmp/test.php 
<?php

var_dump(PHP_OS !== 'WINNT');

var_dump(PHP_OS !== 'WINNT' && (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes));

iTerm2

$ php /tmp/test.php 
bool(true)
bool(true)

jenkins on MacOSX

+ php /tmp/test.php
bool(true)
bool(false) // no supported tty even if OS is not Windows.

@taylorotwell
Copy link
Member

Would like a cleaner solution than this. Just turn off TTY entirely to be honest.

@head1328
Copy link

head1328 commented Feb 21, 2017

I think this is a real problem. Sometimes tty is available but not writeable. I have a similar problem at the moment:

docker-compose exec -T container php artisan dusk or docker exec -ti container php artisan dusk -> TTY mode requires /dev/tty to be read/writable.

Without -T I will run into this issue: docker/compose#3352

Perpaps it's a docker/docker-compose issue and it will be fixed with docker 1.14.

notice perhaps it's a docker-compose issue because this works for me: docker exec -ti container php artisan dusk

@kevin-coyle
Copy link

Yeah I'm getting this issue when trying to run it through Jenkins

@slava-vishnyakov
Copy link

Was this fixed anywhere?

@matrunchyk
Copy link

The same issue when running php artisan dusk in Bitbucket pipeline:

php artisan dusk --colors --debug

[Symfony\Component\Process\Exception\RuntimeException]
TTY mode requires /dev/tty to be read/writable.

@giolf
Copy link

giolf commented Apr 17, 2017

same issue in Gitlab CI

@deleugpn
Copy link
Contributor

Can anybody from this thread confirm if #223 fixes the problem?

@giolf @matrunchyk @mamor

@giolf
Copy link

giolf commented Apr 17, 2017

@deleugpn
building time ... i'll let you know soon ...

@giolf
Copy link

giolf commented Apr 17, 2017

$ php artisan dusk --colors --debug                                                        
  [Symfony\Component\Process\Exception\RuntimeException]  
  TTY mode requires /dev/tty to be read/writable.
  ERROR: Job failed: exit code 1                                                             

IMHO it's a docker's issue.

If i run:
ls -la /dev/tty
in the container of the pipeline i get:
crw-rw-rw-. 1 root root 5, 0 Apr 17 20:28 /dev/tty

it would seem dev/tty has the right permissions
damn, i need a beer.

@matrunchyk
Copy link

@deleugpn I'll give it a try in a few minutes.

@giolf
Copy link

giolf commented Apr 17, 2017

@matrunchyk let me know. By me it still doesn't work.

@matrunchyk
Copy link

@giolf You're right! It doesn't work for me as well.
/dev/tty is writeable (and is_writeable/is_readable return true) but it fails unless I set directly false (as @mamor did). Super weird.

@darkblackart
Copy link

I try run in php file with ssh, but i have this error:

[2] =>   [Symfony\Component\Process\Exception\RuntimeException]  
[3] =>   TTY mode requires /dev/tty to be read/writable.         

Who knows how to fix?

@matrunchyk
Copy link

matrunchyk commented Apr 18, 2017

As a workaround,

  1. Run a command
php artisan make:command RunDusk
  1. Open app/Console/Commands/RunDusk.php
  2. Change declaration class RunDusk extends DuskCommand
  3. Remove all methods and properties from this class and add the only one:
public function handle()
    {
        $this->purgeScreenshots();
        $this->purgeConsoleLogs();
        $options = array_slice($_SERVER['argv'], 2);
        return $this->withDuskEnvironment(function () use ($options) {
            return (new ProcessBuilder())
                ->setTimeout(null)
                ->setPrefix($this->binary())
                ->setArguments($this->phpunitArguments($options))
                ->getProcess()
                ->setTty(false) // <--------------------------- DOES THE TRICK
                ->run(function ($type, $line) {
                    $this->output->write($line);
                });
        });
    }
  1. php artisan dusk

@mamor
Copy link
Author

mamor commented Apr 18, 2017

this problem occurred "Symfony\Component\Process\Process" following line.
https://github.com/symfony/process/blob/master/Process.php#L1039

To solve this problem, should avoid that.

@deleugpn
Copy link
Contributor

deleugpn commented Apr 18, 2017

@mamor I just pushed #226 to supress that exception

@matrunchyk
Copy link

@deleugpn Due to some no-idea-reason it doesn't work.

@deleugpn
Copy link
Contributor

deleugpn commented Apr 18, 2017

@matrunchyk Sorry if I sound rude, but it has no way of not working. What makes you think it doesn't work?

@matrunchyk
Copy link

matrunchyk commented Apr 18, 2017

@deleugpn Ahh sorry, I didn't notice you've changed your original commit. Definitely, now it fixes the issue with TTY.

@mamor
Copy link
Author

mamor commented Apr 18, 2017

@mamor
Copy link
Author

mamor commented Apr 18, 2017

@darkblackart
Copy link

@deleugpn Thanks :D

@giolf
Copy link

giolf commented Apr 18, 2017

@deleugpn thank you 4 your update.
just one question:
When your update would be available in the composer scope ?
at the moment composer updateseems to don't have yet the last merge.

i mean in the new release.

@deleugpn
Copy link
Contributor

@giolf When Taylor tags a new release. I suggest you to stick with dev-master because this package rarely gets any changes and Taylor doesn't release a new tag each pull request. I bet it might take some time until we make a breaking change.

@CoolGoose
Copy link

It seems the problem still exists on CentOS 7.2.1511 using gitlabci with dev-master for dusk (and trying with --colors and --debug)

Warning: TTY mode requires /dev/tty to be read/writable.

The CI does see colors and the tests fail / succeed so not sure if it's something to ignore or not

@deleugpn
Copy link
Contributor

deleugpn commented Jun 2, 2017

@CoolGoose that is just a warning, the fact that the tests are running means the fix worked. Before, CI tools couldn't even run the tests at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants