detached ece7682

broker_stream_window_test.go RawHistoryFolder

1package ports
2
3import (
4	"sync"
5	"testing"
6
7	"github.com/stretchr/testify/require"
8)
9
10// TestBrokerStreamWindowAdmission pins the bounded anti-replay window: a
11// concurrent lower identity that was allocated first is admitted after a higher
12// one, a duplicate inside the window is refused, an identity evicted past the
13// bound is stale, and zero is never a valid identity.
14func TestBrokerStreamWindowAdmission(t *testing.T) {
15	for _, tc := range []struct {
16		name    string
17		admit   []BrokerStreamID
18		wantErr []error
19	}{
20		{
21			name:    "concurrent 2 then 1",
22			admit:   []BrokerStreamID{2, 1},
23			wantErr: []error{nil, nil},
24		},
25		{
26			name:    "duplicate refused",
27			admit:   []BrokerStreamID{2, 2},
28			wantErr: []error{nil, BrokerAdmissionStale},
29		},
30		{
31			name:    "abandoned identity stays consumable",
32			admit:   []BrokerStreamID{3, 1, 2},
33			wantErr: []error{nil, nil, nil},
34		},
35		{
36			name:    "identity inside the window after a high one",
37			admit:   []BrokerStreamID{BrokerStreamWindowSize, 1},
38			wantErr: []error{nil, nil},
39		},
40		{
41			name:    "identity evicted past the window is stale",
42			admit:   []BrokerStreamID{1, BrokerStreamWindowSize + 1, 1},
43			wantErr: []error{nil, nil, BrokerAdmissionStale},
44		},
45		{
46			name:    "boundary identity still admitted",
47			admit:   []BrokerStreamID{1, BrokerStreamWindowSize, 2},
48			wantErr: []error{nil, nil, nil},
49		},
50		{
51			name:    "zero identity refused",
52			admit:   []BrokerStreamID{0},
53			wantErr: []error{BrokerAdmissionInvalid},
54		},
55	} {
56		t.Run(tc.name, func(t *testing.T) {
57			var window BrokerStreamWindow
58			for i, stream := range tc.admit {
59				require.ErrorIs(t, window.Admit(stream), tc.wantErr[i], "admission %d of %d", i, stream)
60			}
61		})
62	}
63}
64
65// TestBrokerStreamWindowConcurrentMonotone proves concurrent allocations admit
66// every distinct identity exactly once and never collide, under the race
67// detector.
68func TestBrokerStreamWindowConcurrentMonotone(t *testing.T) {
69	var window BrokerStreamWindow
70	const count = 512
71	var wg sync.WaitGroup
72	errs := make([]error, count)
73	for i := range count {
74		wg.Add(1)
75		go func() {
76			defer wg.Done()
77			errs[i] = window.Admit(BrokerStreamID(i + 1))
78		}()
79	}
80	wg.Wait()
81	for i, err := range errs {
82		require.NoError(t, err, "identity %d", i+1)
83	}
84	// Replaying one admitted identity is refused.
85	require.ErrorIs(t, window.Admit(1), BrokerAdmissionStale)
86}

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