@@ -835,7 +835,7 @@ func TestCaptureFifoToFile(t *testing.T) {
835
835
m := & Machine {
836
836
exitCh : make (chan struct {}),
837
837
}
838
- if err := m .captureFifoToFile (fctesting .NewLogEntry (t ), fifoPath , testWriter ); err != nil {
838
+ if err := m .captureFifoToFile (context . Background (), fctesting .NewLogEntry (t ), fifoPath , testWriter ); err != nil {
839
839
t .Errorf ("Unexpected error: %v" , err )
840
840
}
841
841
@@ -877,12 +877,19 @@ func TestCaptureFifoToFile_nonblock(t *testing.T) {
877
877
m := & Machine {
878
878
exitCh : make (chan struct {}),
879
879
}
880
- if err := m .captureFifoToFile (fctesting .NewLogEntry (t ), fifoPath , testWriter ); err != nil {
880
+ if err := m .captureFifoToFile (context . Background (), fctesting .NewLogEntry (t ), fifoPath , testWriter ); err != nil {
881
881
t .Errorf ("Unexpected error: %v" , err )
882
882
}
883
883
884
884
defer os .Remove (logPath )
885
885
886
+ // we sleep here to check to see the io.Copy is working properly in
887
+ // captureFifoToFile. This is due to the fifo being opened with O_NONBLOCK,
888
+ // which causes io.Copy to exit immediately with no error.
889
+ //
890
+ // https://github.com/firecracker-microvm/firecracker-go-sdk/issues/156
891
+ time .Sleep (250 * time .Millisecond )
892
+
886
893
f , err := os .OpenFile (fifoPath , os .O_RDWR , 0600 )
887
894
if err != nil {
888
895
t .Fatalf ("Failed to open file, %q: %v" , fifoPath , err )
@@ -1066,14 +1073,20 @@ func TestCaptureFifoToFile_leak(t *testing.T) {
1066
1073
logger := fctesting .NewLogEntry (t )
1067
1074
logger .Logger .Level = logrus .WarnLevel
1068
1075
logger .Logger .Out = loggerBuffer
1069
- err = m .captureFifoToFile (logger , fifoPath , buf )
1076
+ err = m .captureFifoToFile (context . Background (), logger , fifoPath , buf )
1070
1077
assert .NoError (t , err , "failed to capture fifo to file" )
1071
1078
close (m .exitCh )
1072
1079
1073
1080
// wait sometime for the logs to populate
1074
1081
time .Sleep (250 * time .Millisecond )
1075
- expected := `io.Copy failed to copy contents of fifo pipe: read testdata/TestCaptureFifoToFileLeak.fifo: file already closed`
1076
- assert .Contains (t , loggerBuffer .String (), expected )
1082
+ expectedClosedFifo := `reading from a closed fifo`
1083
+ expectedClosedFile := `file already closed`
1084
+ logs := loggerBuffer .String ()
1085
+ if ! (strings .Contains (logs , expectedClosedFifo ) ||
1086
+ strings .Contains (logs , expectedClosedFile )) {
1087
+
1088
+ t .Errorf ("logs did not container a closed fifo error or closed file" )
1089
+ }
1077
1090
}
1078
1091
1079
1092
func TestWaitWithKill (t * testing.T ) {
0 commit comments