main ece7682

preamble_race_test.go RawHistoryFolder

1package sessionwire
2
3import (
4	"io"
5	"testing"
6
7	"github.com/stretchr/testify/require"
8
9	"github.com/bnema/vev/internal/protocol/wire"
10)
11
12// failingTransport fails every receive, so the lazy preamble settles quickly
13// while still writing the ceilings it negotiated.
14type failingTransport struct{}
15
16func (failingTransport) Send(wire.Envelope) error     { return nil }
17func (failingTransport) Recv() (wire.Envelope, error) { return wire.Envelope{}, io.EOF }
18func (failingTransport) Close() error                 { return nil }
19
20// TestCapabilitiesReadIsSafeDuringPreamble proves a caller may ask for
21// capabilities while another goroutine is establishing the preamble.
22//
23// The preamble is lazy: whoever first uses the connection runs it, and it
24// publishes the negotiated ceilings. A capabilities read does not go through
25// that once, so it needs the same lock the publication takes; without it the
26// read races with the write, which is exactly what a real offline composition
27// reported under the race detector.
28func TestCapabilitiesReadIsSafeDuringPreamble(t *testing.T) {
29	connection := NewClientConnection(failingTransport{})
30	require.NotNil(t, connection)
31
32	done := make(chan struct{})
33	go func() {
34		defer close(done)
35		_, _ = connection.ReceiveServer()
36	}()
37
38	// Read capabilities for the whole window in which the preamble publishes.
39	for {
40		select {
41		case <-done:
42			return
43		default:
44			_ = connection.Capabilities()
45		}
46	}
47}
48
49// TestServerCapabilitiesReadIsSafeDuringPreamble is the server-side twin: the
50// daemon-facing connection has the same lazy publication and the same unlocked
51// capabilities read.
52func TestServerCapabilitiesReadIsSafeDuringPreamble(t *testing.T) {
53	connection, ok := NewServerConnection(failingTransport{}).(*serverConnection)
54	require.True(t, ok)
55
56	done := make(chan struct{})
57	go func() {
58		defer close(done)
59		_, _ = connection.ReceiveClient()
60	}()
61
62	for {
63		select {
64		case <-done:
65			return
66		default:
67			_ = connection.Capabilities()
68		}
69	}
70}

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