@@ -1076,37 +1076,18 @@ func TestCaptureFifoToFile_leak(t *testing.T) {
10761076 assert .Contains (t , loggerBuffer .String (), expected )
10771077}
10781078
1079- func TestWait (t * testing.T ) {
1079+ func TestWaitWithKill (t * testing.T ) {
10801080 fctesting .RequiresRoot (t )
10811081 ctx := context .Background ()
10821082
10831083 socketPath := filepath .Join (testDataPath , t .Name ())
10841084 defer os .Remove (socketPath )
10851085
1086- cfg := Config {
1087- SocketPath : socketPath ,
1088- KernelImagePath : getVmlinuxPath (t ),
1089- MachineCfg : models.MachineConfiguration {
1090- VcpuCount : Int64 (2 ),
1091- CPUTemplate : models .CPUTemplate (models .CPUTemplateT2 ),
1092- MemSizeMib : Int64 (256 ),
1093- HtEnabled : Bool (false ),
1094- },
1095- Drives : []models.Drive {
1096- {
1097- DriveID : String ("root" ),
1098- IsRootDevice : Bool (true ),
1099- IsReadOnly : Bool (true ),
1100- PathOnHost : String (testRootfs ),
1101- },
1102- },
1103- }
1104-
1086+ cfg := createValidConfig (t , socketPath )
11051087 cmd := VMCommandBuilder {}.
11061088 WithSocketPath (cfg .SocketPath ).
11071089 WithBin (getFirecrackerBinaryPath ()).
11081090 Build (ctx )
1109-
11101091 m , err := NewMachine (ctx , cfg , WithProcessRunner (cmd ))
11111092 require .NoError (t , err )
11121093
@@ -1127,3 +1108,82 @@ func TestWait(t *testing.T) {
11271108 err = m .Wait (ctx )
11281109 require .Error (t , err , "Firecracker was killed and it must be reported" )
11291110}
1111+
1112+ func TestWaitWithInvalidBinary (t * testing.T ) {
1113+ ctx := context .Background ()
1114+
1115+ socketPath := filepath .Join (testDataPath , t .Name ())
1116+ defer os .Remove (socketPath )
1117+
1118+ cfg := createValidConfig (t , socketPath )
1119+ cmd := VMCommandBuilder {}.
1120+ WithSocketPath (socketPath ).
1121+ WithBin ("invalid-bin" ).
1122+ Build (ctx )
1123+ m , err := NewMachine (ctx , cfg , WithProcessRunner (cmd ))
1124+ require .NoError (t , err )
1125+
1126+ ch := make (chan error )
1127+
1128+ go func () {
1129+ err := m .Wait (ctx )
1130+ require .Error (t , err , "Wait() reports an error" )
1131+ ch <- err
1132+ }()
1133+
1134+ err = m .Start (ctx )
1135+ require .Error (t , err , "Start() reports an error" )
1136+
1137+ select {
1138+ case errFromWait := <- ch :
1139+ require .Equal (t , errFromWait , err )
1140+ }
1141+ }
1142+
1143+ func TestWaitWithNoSocket (t * testing.T ) {
1144+ ctx := context .Background ()
1145+
1146+ socketPath := filepath .Join (testDataPath , t .Name ())
1147+ defer os .Remove (socketPath )
1148+ cfg := createValidConfig (t , socketPath )
1149+
1150+ m , err := NewMachine (ctx , cfg , WithProcessRunner (exec .Command ("sleep" , "10" )))
1151+ require .NoError (t , err )
1152+
1153+ ch := make (chan error )
1154+
1155+ go func () {
1156+ err := m .Wait (ctx )
1157+ require .Error (t , err , "Wait() reports an error" )
1158+ ch <- err
1159+ }()
1160+
1161+ err = m .Start (ctx )
1162+ require .Error (t , err , "Start() reports an error" )
1163+
1164+ select {
1165+ case errFromWait := <- ch :
1166+ require .Equal (t , errFromWait , err )
1167+ }
1168+ }
1169+
1170+ func createValidConfig (t * testing.T , socketPath string ) Config {
1171+ return Config {
1172+ SocketPath : socketPath ,
1173+ KernelImagePath : getVmlinuxPath (t ),
1174+ MachineCfg : models.MachineConfiguration {
1175+ VcpuCount : Int64 (2 ),
1176+ CPUTemplate : models .CPUTemplate (models .CPUTemplateT2 ),
1177+ MemSizeMib : Int64 (256 ),
1178+ HtEnabled : Bool (false ),
1179+ },
1180+ Drives : []models.Drive {
1181+ {
1182+ DriveID : String ("root" ),
1183+ IsRootDevice : Bool (true ),
1184+ IsReadOnly : Bool (true ),
1185+ PathOnHost : String (testRootfs ),
1186+ },
1187+ },
1188+ }
1189+ }
0 commit comments