Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1321e8f401 |
+17
-2
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -428,9 +429,23 @@ func TestGPGTimeoutKillsGPG(t *testing.T) {
|
|||||||
// child instead of exec-ing it, the way a wrapper script around the real
|
// child instead of exec-ing it, the way a wrapper script around the real
|
||||||
// gpg might. Killing the fake gpg leaves sleep holding its stdout and
|
// gpg might. Killing the fake gpg leaves sleep holding its stdout and
|
||||||
// stderr open; the call must still return shortly after the deadline
|
// stderr open; the call must still return shortly after the deadline
|
||||||
// instead of waiting for sleep to exit.
|
// instead of waiting for sleep to exit. The fake gpg writes the process ID
|
||||||
|
// of sleep to a file so that the test can kill it before returning.
|
||||||
func TestGPGTimeoutWhenChildHoldsOutput(t *testing.T) {
|
func TestGPGTimeoutWhenChildHoldsOutput(t *testing.T) {
|
||||||
t.Setenv("PATH", fakeGPGPath(t, "#!/bin/sh\nsleep 3\nexit\n"))
|
pidFile := filepath.Join(t.TempDir(), "sleep.pid")
|
||||||
|
t.Setenv("PATH", fakeGPGPath(t,
|
||||||
|
"#!/bin/sh\nsleep 3 &\necho $! >'"+pidFile+"'\nwait\n"))
|
||||||
|
t.Cleanup(func() {
|
||||||
|
pid, err := os.ReadFile(pidFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
n, err := strconv.Atoi(strings.TrimSpace(string(pid)))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
sleep, err := os.FindProcess(n)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, sleep.Kill())
|
||||||
|
})
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
Reference in New Issue
Block a user