|
1 | 1 | package exec |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "os" |
5 | 4 | "os/exec" |
6 | | - "path/filepath" |
7 | 5 | "regexp" |
8 | 6 | "syscall" |
9 | 7 | "testing" |
@@ -219,51 +217,3 @@ func TestRunCaptureStderr(t *testing.T) { |
219 | 217 | assert.Equal(t, "hello world\nmy-error", output) |
220 | 218 | assert.NoError(t, err) |
221 | 219 | } |
222 | | - |
223 | | -// This test demonstrates that when a process group is signaled, all child processes are also terminated and file locks released. |
224 | | -func TestProcessGroupSignalRemovesChildLock(t *testing.T) { |
225 | | - hook := test.NewGlobal() |
226 | | - log.SetLevel(log.DebugLevel) |
227 | | - defer log.SetLevel(log.InfoLevel) |
228 | | - |
229 | | - dir := t.TempDir() |
230 | | - lockFile := filepath.Join(dir, "lockfile") |
231 | | - childScript := filepath.Join(dir, "child.sh") |
232 | | - parentScript := filepath.Join(dir, "parent.sh") |
233 | | - |
234 | | - // Child: create lock file; on SIGTERM remove it and exit |
235 | | - child := "#!/bin/sh\n" + |
236 | | - "trap 'rm -f lockfile; exit 0' TERM\n" + |
237 | | - "touch lockfile\n" + |
238 | | - "sleep 100\n" |
239 | | - require.NoError(t, os.WriteFile(childScript, []byte(child), 0o755)) |
240 | | - |
241 | | - // Parent: start child in background and sleep |
242 | | - parent := "#!/bin/sh\n" + |
243 | | - "./child.sh &\n" + |
244 | | - "sleep 100\n" |
245 | | - require.NoError(t, os.WriteFile(parentScript, []byte(parent), 0o755)) |
246 | | - |
247 | | - // Run parent with a short timeout; our implementation signals the process group |
248 | | - opts := CmdOpts{ |
249 | | - Timeout: 500 * time.Millisecond, |
250 | | - FatalTimeout: 500 * time.Millisecond, |
251 | | - TimeoutBehavior: TimeoutBehavior{ |
252 | | - Signal: syscall.SIGTERM, |
253 | | - ShouldWait: true, |
254 | | - }, |
255 | | - } |
256 | | - _, err := RunCommand("sh", opts, "-c", "cd "+dir+" && ./parent.sh") |
257 | | - require.Error(t, err) |
258 | | - |
259 | | - // Give a bit of time for traps to run and for the process tree to settle |
260 | | - time.Sleep(200 * time.Millisecond) |
261 | | - |
262 | | - // Because the process group was signaled, the child should have removed the lock |
263 | | - _, statErr := os.Stat(lockFile) |
264 | | - require.Error(t, statErr, "expected lock file to be removed when process group is signaled") |
265 | | - assert.True(t, os.IsNotExist(statErr)) |
266 | | - |
267 | | - // basic sanity: logs produced |
268 | | - require.GreaterOrEqual(t, len(hook.Entries), 1) |
269 | | -} |
0 commit comments