Unable to run golang test that opens pseudoterminal from Github action- read /dev/ptmx: input/output error

24 Views Asked by At

I'm trying to run this test from a github action pipline, that uses this lib to open pseudoterminal:

func TestMysqlConnect(t *testing.T) {
    ctx, cancel := context.WithTimeout(context.Background(), connectTimeout)
    defer cancel()


    cmd := exec.CommandContext(ctx, "xxx", "connect", ...)

    t.Logf("About to run connect command %q", cmd.String())

    ptmx, err := pty.Start(cmd)
    require.NoErrorf(t, err, "Failed to start pseudoterminal")
    defer func() { _ = ptmx.Close() }()

    go func() {
        ptmx.Write([]byte("SELECT 1;\n"))
        ptmx.Write([]byte{4})
    }()

    var buff bytes.Buffer
    _, err = io.Copy(&buff, ptmx)
    require.NoError(t, err)

    require.Contains(t, buff.String(), "1 row in set")
}

The command "xxx" is a CLI command that essentially opens an SSH session to some target (that opens a mysql CLI). This is the command that the test checks. When I run it locally (in apple m2) it works, however when I run it from github action I get this error message: read /dev/ptmx: input/output error, from the io.Copy operation.
The action run with ubuntu 22.04 image.
What can be the issue? Or how can I get more details about the error? "input/output" error message is very general, every error related to files is usually "input/output" error... I tried to extract data from the error, it is of type fs.PathError, but this type include the fields OP=read, Path=/dev/ptmx Err=input/output, it doesn't give me extra information for debugging.
I already tried to run it with shell: 'script -q -e -c "bash {0}"' (saw suggestions in the web) but I get the same error.

- name: run integration test
  shell: 'script -q -e -c "bash {0}"'
  run: go test -run Test ./services/some-service -tags=integration
  • I don't have control on the internal logic of xxx command, I can't for example change the SSH command there and add -t flag

  • The file have (I think) correct read/permissions Dcrw-rw-rw-

0

There are 0 best solutions below