runtime: Fix random failure for TestIoCopy

When running the TestIoCopy test, on some occasions, the test
runs too quick, and closes the stdin pipe before the ioCopy()
routine start to read from it. This causes a SIGSEGV error.

To fix this issue, I am adding additional read/write tests before
closing the pipes. As the read operation waits for the writer to
be done, this actually synchronizes the threads and make sure
the final tests (with closed pipes) works as expected.

Fixes: #2042

Signed-off-by: Julien Ropé <jrope@redhat.com>
This commit is contained in:
Julien Ropé 2021-06-16 11:34:09 +02:00
parent db7d3b91bd
commit 17a8c5c685

View File

@ -91,8 +91,6 @@ func TestNewTtyIOFifoReopen(t *testing.T) {
}
func TestIoCopy(t *testing.T) {
t.Skip("TestIoCopy is failing randonly, see https://github.com/kata-containers/kata-containers/issues/2042")
assert := assert.New(t)
ctx := context.TODO()
@ -229,6 +227,18 @@ func TestIoCopy(t *testing.T) {
}
}
// check everything works without closed pipes
checkFifoWrite(firstW, testBytes1, first)
checkFifoRead(firstR, testBytes1, first)
checkFifoWrite(secondW, testBytes2, second)
checkFifoRead(secondR, testBytes2, second)
if thirdW != nil {
checkFifoWrite(thirdW, testBytes3, third)
checkFifoRead(thirdR, testBytes3, third)
}
// write to each pipe, and close them immediately
// the ioCopy function should copy the data, then stop the corresponding thread
checkFifoWrite(firstW, testBytes1, first)