liveness_test.go RawHistoryFolder

1package process
2
3import (
4	"context"
5	"errors"
6	"os"
7	"syscall"
8	"testing"
9
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12)
13
14func TestLivenessProbe_IsProcessAliveRejectsInvalidPID(t *testing.T) {
15	t.Parallel()
16
17	probe := &LivenessProbe{signal: func(_ int, _ os.Signal) error {
18		t.Fatal("signal should not be called for invalid pid")
19		return nil
20	}}
21
22	alive, err := probe.IsProcessAlive(context.Background(), 0)
23
24	assert.False(t, alive)
25	require.Error(t, err)
26	assert.Contains(t, err.Error(), "invalid pid")
27}
28
29func TestLivenessProbe_IsProcessAliveReturnsContextErrorBeforeSignaling(t *testing.T) {
30	t.Parallel()
31
32	ctx, cancel := context.WithCancel(context.Background())
33	cancel()
34	probe := &LivenessProbe{signal: func(_ int, _ os.Signal) error {
35		t.Fatal("signal should not be called when context is canceled")
36		return nil
37	}}
38
39	alive, err := probe.IsProcessAlive(ctx, 1234)
40
41	assert.False(t, alive)
42	require.ErrorIs(t, err, context.Canceled)
43}
44
45func TestLivenessProbe_IsProcessAliveInterpretsSignalErrors(t *testing.T) {
46	t.Parallel()
47
48	tests := []struct {
49		name      string
50		signalErr error
51		wantAlive bool
52		wantErr   error
53	}{
54		{name: "signal succeeds", wantAlive: true},
55		{name: "process missing", signalErr: syscall.ESRCH, wantAlive: false},
56		{name: "permission denied means process exists", signalErr: syscall.EPERM, wantAlive: true},
57		{name: "unexpected signal error propagates", signalErr: errors.New("signal failed"), wantAlive: false, wantErr: errors.New("signal failed")},
58	}
59
60	for _, tt := range tests {
61		t.Run(tt.name, func(t *testing.T) {
62			t.Parallel()
63
64			probe := &LivenessProbe{signal: func(pid int, signal os.Signal) error {
65				assert.Equal(t, 1234, pid)
66				assert.Equal(t, syscall.Signal(0), signal)
67				return tt.signalErr
68			}}
69
70			alive, err := probe.IsProcessAlive(context.Background(), 1234)
71
72			assert.Equal(t, tt.wantAlive, alive)
73			if tt.wantErr != nil {
74				require.Error(t, err)
75				assert.EqualError(t, err, tt.wantErr.Error())
76			} else {
77				require.NoError(t, err)
78			}
79		})
80	}
81}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close