(t *testing.T)
| 23 | var SLEEPIT, _ = filepath.Abs("./bin/sleepit") |
| 24 | |
| 25 | func TestSignalSentToProcessGroup(t *testing.T) { |
| 26 | task, err := getTaskPath() |
| 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | |
| 31 | testCases := map[string]struct { |
| 32 | args []string |
| 33 | sendSigs int |
| 34 | want []string |
| 35 | notWant []string |
| 36 | }{ |
| 37 | // regression: |
| 38 | // - child is terminated, immediately, by "context canceled" (another bug???) |
| 39 | "child does not handle sigint: receives sigint and terminates immediately": { |
| 40 | args: []string{task, "--", SLEEPIT, "default", "-sleep=10s"}, |
| 41 | sendSigs: 1, |
| 42 | want: []string{ |
| 43 | "sleepit: ready\n", |
| 44 | "sleepit: work started\n", |
| 45 | "task: Signal received: \"interrupt\"\n", |
| 46 | // 130 = 128 + SIGINT |
| 47 | "task: Failed to run task \"default\": exit status 130\n", |
| 48 | }, |
| 49 | notWant: []string{ |
| 50 | "task: Failed to run task \"default\": context canceled\n", |
| 51 | }, |
| 52 | }, |
| 53 | // 2 regressions: |
| 54 | // - child receives 2 signals instead of 1 |
| 55 | // - child is terminated, immediately, by "context canceled" (another bug???) |
| 56 | // TODO we need -cleanup=2s only to show reliably the bug; once the fix is committed, |
| 57 | // we can use -cleanup=50ms to speed the test up |
| 58 | "child intercepts sigint: receives sigint and does cleanup": { |
| 59 | args: []string{task, "--", SLEEPIT, "handle", "-sleep=10s", "-cleanup=2s"}, |
| 60 | sendSigs: 1, |
| 61 | want: []string{ |
| 62 | "sleepit: ready\n", |
| 63 | "sleepit: work started\n", |
| 64 | "task: Signal received: \"interrupt\"\n", |
| 65 | "sleepit: got signal=interrupt count=1\n", |
| 66 | "sleepit: work canceled\n", |
| 67 | "sleepit: cleanup started\n", |
| 68 | "sleepit: cleanup done\n", |
| 69 | "task: Failed to run task \"default\": exit status 3\n", |
| 70 | }, |
| 71 | notWant: []string{ |
| 72 | "sleepit: got signal=interrupt count=2\n", |
| 73 | "task: Failed to run task \"default\": context canceled\n", |
| 74 | }, |
| 75 | }, |
| 76 | // regression: child receives 2 signal instead of 1 and thus terminates abruptly |
| 77 | "child simulates terraform: receives 1 sigint and does cleanup": { |
| 78 | args: []string{task, "--", SLEEPIT, "handle", "-term-after=2", "-sleep=10s", "-cleanup=50ms"}, |
| 79 | sendSigs: 1, |
| 80 | want: []string{ |
| 81 | "sleepit: ready\n", |
| 82 | "sleepit: work started\n", |
nothing calls this directly
no test coverage detected
searching dependent graphs…