@@ -122,8 +122,16 @@ void testKillProcessSuccessWithNoAlivePids() {
122122 Mockito .when (taskRequest .getTenantCode ()).thenReturn ("testTenant" );
123123
124124 // Mock getPidsStr
125- mockedOSUtils .when (() -> OSUtils .exeCmd (Mockito .matches (".*pstree.*12345" )))
126- .thenReturn ("sudo(12345)---86.sh(1234)" );
125+ String pstreeCmd ;
126+ String pstreeOutput ;
127+ if (SystemUtils .IS_OS_MAC ) {
128+ pstreeCmd = "pstree -sp 12345" ;
129+ pstreeOutput = "-+= 12345 sudo -+- 1234 86.sh" ;
130+ } else {
131+ pstreeCmd = "pstree -p 12345" ;
132+ pstreeOutput = "sudo(12345)---86.sh(1234)" ;
133+ }
134+ mockedOSUtils .when (() -> OSUtils .exeCmd (pstreeCmd )).thenReturn (pstreeOutput );
127135
128136 // Mock kill -0
129137 mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -0.*" )))
@@ -138,9 +146,9 @@ void testKillProcessSuccessWithNoAlivePids() {
138146 Assertions .assertTrue (result );
139147
140148 // Verify SIGINT, SIGTERM, SIGKILL never called
141- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGINT 12345" ), Mockito .never ());
142- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGTERM 12345" ), Mockito .never ());
143- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGKILL 12345" ), Mockito .never ());
149+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -2 12345 1234 " ), Mockito .never ());
150+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -15 12345 1234 " ), Mockito .never ());
151+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -9 12345 1234 " ), Mockito .never ());
144152 }
145153
146154 @ Test
@@ -151,17 +159,26 @@ void testKillProcessSuccessWithSigInt() {
151159 Mockito .when (taskRequest .getTenantCode ()).thenReturn ("testTenant" );
152160
153161 // Mock getPidsStr
154- mockedOSUtils .when (() -> OSUtils .exeCmd (Mockito .matches (".*pstree.*12345" )))
155- .thenReturn ("sudo(12345)---86.sh(1234)" );
162+ String pstreeCmd ;
163+ String pstreeOutput ;
164+ if (SystemUtils .IS_OS_MAC ) {
165+ pstreeCmd = "pstree -sp 12345" ;
166+ pstreeOutput = "-+= 12345 sudo -+- 1234 86.sh" ;
167+ } else {
168+ pstreeCmd = "pstree -p 12345" ;
169+ pstreeOutput = "sudo(12345)---86.sh(1234)" ;
170+ }
171+ mockedOSUtils .when (() -> OSUtils .exeCmd (pstreeCmd )).thenReturn (pstreeOutput );
156172
157173 // Mock SIGINT command
158- mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -s SIGINT .*" )))
159- .thenReturn ("kill -s SIGINT 12345" );
160- mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -s SIGINT 12345" )).thenReturn ("" );
174+ mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -2 .*" )))
175+ .thenReturn ("kill -2 12345 1234 " );
176+ mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -2 12345 1234 " )).thenReturn ("" );
161177
162178 // Mock kill -0
163179 mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -0.*" )))
164- .thenReturn ("kill -0 12345" );
180+ .thenReturn ("kill -0 12345" )
181+ .thenReturn ("kill -0 1234" );
165182 // Mock the static method OSUtils.exeCmd that matches "kill -0" command
166183 mockedOSUtils .when (() -> OSUtils .exeCmd (Mockito .matches (".*kill -0.*" )))
167184 .thenReturn ("" ) // First invocation succeeds (process is alive)
@@ -176,10 +193,10 @@ void testKillProcessSuccessWithSigInt() {
176193 Assertions .assertTrue (result );
177194
178195 // Verify SIGINT was called
179- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGINT 12345" ), Mockito .times (1 ));
196+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -2 12345 1234 " ), Mockito .times (1 ));
180197 // Verify SIGTERM,SIGKILL was never called
181- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGTERM 12345" ), Mockito .never ());
182- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGKILL 12345" ), Mockito .never ());
198+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -15 12345 1234 " ), Mockito .never ());
199+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -9 12345 1234 " ), Mockito .never ());
183200 }
184201
185202 @ Test
@@ -190,27 +207,36 @@ void testKillProcessFail() {
190207 Mockito .when (taskRequest .getTenantCode ()).thenReturn ("testTenant" );
191208
192209 // Mock getPidsStr
193- mockedOSUtils .when (() -> OSUtils .exeCmd (Mockito .matches (".*pstree.*12345" )))
194- .thenReturn ("sudo(12345)---86.sh(1234)" );
210+ String pstreeCmd ;
211+ String pstreeOutput ;
212+ if (SystemUtils .IS_OS_MAC ) {
213+ pstreeCmd = "pstree -sp 12345" ;
214+ pstreeOutput = "-+= 12345 sudo -+- 1234 86.sh" ;
215+ } else {
216+ pstreeCmd = "pstree -p 12345" ;
217+ pstreeOutput = "sudo(12345)---86.sh(1234)" ;
218+ }
219+ mockedOSUtils .when (() -> OSUtils .exeCmd (pstreeCmd )).thenReturn (pstreeOutput );
195220
196221 // Mock SIGINT command
197- mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -s SIGINT .*" )))
198- .thenReturn ("kill -s SIGINT 12345" );
199- mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -s SIGINT 12345" )).thenReturn ("" );
222+ mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -2 .*" )))
223+ .thenReturn ("kill -2 12345 1234 " );
224+ mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -2 12345 1234 " )).thenReturn ("" );
200225
201226 // Mock SIGTERM command
202- mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -s SIGTERM .*" )))
203- .thenReturn ("kill -s SIGTERM 12345" );
204- mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -s SIGTERM 12345" )).thenReturn ("" );
227+ mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -15 .*" )))
228+ .thenReturn ("kill -15 12345 1234 " );
229+ mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -15 12345 1234 " )).thenReturn ("" );
205230
206231 // Mock SIGKILL command
207- mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -s SIGKILL .*" )))
208- .thenReturn ("kill -s SIGKILL 12345" );
209- mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -s SIGKILL 12345" )).thenReturn ("" );
232+ mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -9 .*" )))
233+ .thenReturn ("kill -9 12345 1234 " );
234+ mockedOSUtils .when (() -> OSUtils .exeCmd ("kill -9 12345 1234 " )).thenReturn ("" );
210235
211236 // Mock kill -0
212237 mockedOSUtils .when (() -> OSUtils .getSudoCmd (Mockito .eq ("testTenant" ), Mockito .matches ("kill -0.*" )))
213- .thenReturn ("kill -0 12345" );
238+ .thenReturn ("kill -0 12345" )
239+ .thenReturn ("kill -0 1234" );
214240 mockedOSUtils .when (() -> OSUtils .exeCmd (Mockito .matches (".*kill -0.*" ))).thenReturn ("" );
215241
216242 // Act
@@ -220,9 +246,9 @@ void testKillProcessFail() {
220246 Assertions .assertFalse (result );
221247
222248 // Verify SIGINT, SIGTERM, SIGKILL was called
223- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGINT 12345" ), Mockito .times (1 ));
224- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGTERM 12345" ), Mockito .times (1 ));
225- mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -s SIGKILL 12345" ), Mockito .times (1 ));
249+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -2 12345 1234 " ), Mockito .times (1 ));
250+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -15 12345 1234 " ), Mockito .times (1 ));
251+ mockedOSUtils .verify (() -> OSUtils .exeCmd ("kill -9 12345 1234 " ), Mockito .times (1 ));
226252 }
227253
228254 @ Test
0 commit comments