lease_callback_guard_test.go RawHistoryFolder

1package daemon
2
3import (
4	"runtime"
5	"testing"
6	"time"
7
8	"github.com/stretchr/testify/require"
9
10	"github.com/bnema/vev/internal/domain"
11)
12
13func TestResizeAndRetryCallbacksRejectSameObjectLeaseReplacement(t *testing.T) {
14	for _, tc := range []struct {
15		name     string
16		schedule func(*renderCoordinator, *attachedClient, *attachmentLease, func())
17		done     func(*testing.T, *renderCoordinator) <-chan struct{}
18	}{
19		{
20			name: "resize",
21			schedule: func(rc *renderCoordinator, ac *attachedClient, lease *attachmentLease, run func()) {
22				rc.scheduleResizeForLease(domain.Size{Cols: 100, Rows: 30}, ac, lease, func(uint64) { run() })
23			},
24			done: captureResizeCallbackDone,
25		},
26		{
27			name: "retry",
28			schedule: func(rc *renderCoordinator, ac *attachedClient, lease *attachmentLease, run func()) {
29				epoch := rc.recordResizeRequestForLease(domain.Size{Cols: 100, Rows: 30}, ac, lease)
30				require.NotZero(t, epoch)
31				require.True(t, rc.resizeCurrentForLease(epoch, ac, lease, true))
32				rc.scheduleResizeRetryForLease(epoch, ac, lease, run)
33			},
34			done: func(t *testing.T, rc *renderCoordinator) <-chan struct{} {
35				t.Helper()
36				rc.mu.Lock()
37				defer rc.mu.Unlock()
38				if rc.retryLane.token == nil {
39					t.Fatal("coordinator did not publish a retry callback completion")
40				}
41				return rc.retryLane.token.done
42			},
43		},
44	} {
45		t.Run(tc.name, func(t *testing.T) {
46			clock := newCoordinatorMockClock(t, 1)
47			rc := newRenderCoordinator(renderCoordinatorOptions{clock: clock.clock})
48			ac := &attachedClient{}
49			rc.attach(ac)
50			lease := rc.attachmentLease(ac)
51			ran := false
52			tc.schedule(rc, ac, lease, func() { ran = true })
53			timer := awaitCoordinatorScheduledTimer(t, clock)
54			done := tc.done(t, rc)
55			require.NotNil(t, done)
56
57			rc.noteDetach(ac)
58			rc.attach(ac) // resume the exact same object under a new incarnation
59			timer.ch <- time.Time{}
60			awaitTestCompletion(t, done, "stale callback did not complete")
61			for range 32 {
62				runtime.Gosched()
63			}
64			require.False(t, ran, "stale %s callback ran after lease replacement", tc.name)
65		})
66	}
67}

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 12

Tags 11

↑↓ moveenter openesc close