github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/prog/progtest/progtest_test.go (about) 1 package progtest 2 3 import ( 4 "testing" 5 ) 6 7 // Verify we don't deadlock if more output is written to stdout than can be 8 // buffered by a pipe. 9 func TestOutputCaptureDoesNotDeadlock(t *testing.T) { 10 t.Helper() 11 f := Setup() 12 13 // We need enough data to verify whether we're likely to deadlock due to 14 // filling the pipe before the test completes. Pipes typically buffer 8 to 15 // 128 KiB. 16 bytes := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} 17 for i := 0; i < 128*1024/len(bytes); i++ { 18 f.pipes[1].w.Write(bytes[:]) 19 } 20 f.pipes[1].w.WriteString("hello\n") 21 f.TestOutSnippet(t, 1, "hello") 22 f.TestOut(t, 2, "") 23 }