@@ -56,6 +56,70 @@ void watchdogStartFailureStillCleansOwnedChildAndReleasesPermit() throws Excepti
5656 assertEquals (2 , starts [0 ]);
5757 }
5858
59+ @ Test
60+ void watchdogCreationFailureAfterSpawnStillCleansChildAndReleasesPermit () throws Exception {
61+ int [] starts = new int [1 ];
62+ int [] watchdogCreations = new int [1 ];
63+ FakeProcess [] last = new FakeProcess [1 ];
64+ SubprocessExecutionSupport .Runtime runtime = new SubprocessExecutionSupport .Runtime (1 ,
65+ builder -> {
66+ starts [0 ]++;
67+ last [0 ] = new FakeProcess (false );
68+ return last [0 ];
69+ }, timeout -> {
70+ if (++watchdogCreations [0 ] % 2 == 0 ) {
71+ throw new IllegalStateException ("injected watchdog creation failure" );
72+ }
73+ return new FakeWatchdog (false );
74+ });
75+
76+ for (int attempt = 0 ; attempt < 2 ; attempt ++) {
77+ SubprocessExecutionSupport .ExecutionRequest request = new SubprocessExecutionSupport .ExecutionRequest (
78+ CommandLine .parse ("fake" ), null , null , 1000L , 16 , 16 , 200L ,
79+ System .nanoTime (), new OpenCliCancellationToken ());
80+
81+ SubprocessExecutionSupport .RunSession session = runtime .execute (request );
82+
83+ assertEquals (TerminationReason .IO_FAILURE ,
84+ session .getExecutionDetails ().getTerminationReason ());
85+ assertInstanceOf (IllegalStateException .class , session .getIoFailure ().getCause ());
86+ assertEquals (CleanupState .ROOT_EXIT_CONFIRMED ,
87+ session .getExecutionDetails ().getCleanupState ());
88+ assertFalse (last [0 ].isAlive ());
89+ assertFalse (runtime .isQuarantined ());
90+ }
91+ assertEquals (2 , starts [0 ]);
92+ }
93+
94+ @ Test
95+ void processStreamSetupFailureStillCleansChildAndReleasesPermit () throws Exception {
96+ int [] starts = new int [1 ];
97+ FakeProcess [] last = new FakeProcess [1 ];
98+ SubprocessExecutionSupport .Runtime runtime = new SubprocessExecutionSupport .Runtime (1 ,
99+ builder -> {
100+ starts [0 ]++;
101+ last [0 ] = new FakeProcess (false , false , true );
102+ return last [0 ];
103+ }, timeout -> new FakeWatchdog (false ));
104+
105+ for (int attempt = 0 ; attempt < 2 ; attempt ++) {
106+ SubprocessExecutionSupport .ExecutionRequest request = new SubprocessExecutionSupport .ExecutionRequest (
107+ CommandLine .parse ("fake" ), null , null , 1000L , 16 , 16 , 200L ,
108+ System .nanoTime (), new OpenCliCancellationToken ());
109+
110+ SubprocessExecutionSupport .RunSession session = runtime .execute (request );
111+
112+ assertEquals (TerminationReason .IO_FAILURE ,
113+ session .getExecutionDetails ().getTerminationReason ());
114+ assertInstanceOf (IllegalStateException .class , session .getIoFailure ().getCause ());
115+ assertEquals (CleanupState .ROOT_EXIT_CONFIRMED ,
116+ session .getExecutionDetails ().getCleanupState ());
117+ assertFalse (last [0 ].isAlive ());
118+ assertFalse (runtime .isQuarantined ());
119+ }
120+ assertEquals (2 , starts [0 ]);
121+ }
122+
59123 @ Test
60124 void unconfirmedForcedStopQuarantinesRuntimeWithoutFabricatingExit () throws Exception {
61125 OpenCliCancellationToken token = new OpenCliCancellationToken ();
@@ -157,16 +221,27 @@ private static final class FakeProcess extends Process {
157221 private boolean alive = true ;
158222
159223 private final boolean failForce ;
224+ private final boolean failStreamSetup ;
160225
161- FakeProcess (boolean failDestroy ) { this (failDestroy , false ); }
226+ FakeProcess (boolean failDestroy ) { this (failDestroy , false , false ); }
162227
163228 FakeProcess (boolean failDestroy , boolean failForce ) {
229+ this (failDestroy , failForce , false );
230+ }
231+
232+ FakeProcess (boolean failDestroy , boolean failForce , boolean failStreamSetup ) {
164233 this .failDestroy = failDestroy ;
165234 this .failForce = failForce ;
235+ this .failStreamSetup = failStreamSetup ;
166236 }
167237
168238 @ Override
169- public OutputStream getOutputStream () { return new ByteArrayOutputStream (); }
239+ public OutputStream getOutputStream () {
240+ if (failStreamSetup ) {
241+ throw new IllegalStateException ("injected process stream setup failure" );
242+ }
243+ return new ByteArrayOutputStream ();
244+ }
170245
171246 @ Override
172247 public InputStream getInputStream () { return new ByteArrayInputStream (new byte [0 ]); }
0 commit comments