clock_test.go RawHistoryFolder

1package quicnettest
2
3import (
4	"testing"
5	"time"
6)
7
8func TestManualClockFiresTimersInDeadlineOrder(t *testing.T) {
9	start := time.Unix(0, 0)
10	clock := NewManualClock(start)
11	late := clock.NewTimer(10 * time.Millisecond)
12	early := clock.NewTimer(5 * time.Millisecond)
13
14	clock.Advance(4 * time.Millisecond)
15	expectNoFire(t, early)
16	expectNoFire(t, late)
17
18	clock.Advance(time.Millisecond)
19	expectFire(t, early, start.Add(5*time.Millisecond))
20	expectNoFire(t, late)
21
22	clock.Advance(5 * time.Millisecond)
23	expectFire(t, late, start.Add(10*time.Millisecond))
24}
25
26func TestManualClockFiresEqualDeadlinesInCreationOrder(t *testing.T) {
27	start := time.Unix(0, 0)
28	clock := NewManualClock(start)
29	first := clock.NewTimer(5 * time.Millisecond)
30	second := clock.NewTimer(5 * time.Millisecond)
31
32	clock.Advance(5 * time.Millisecond)
33	expectFire(t, first, start.Add(5*time.Millisecond))
34	expectFire(t, second, start.Add(5*time.Millisecond))
35}
36
37func TestManualClockStopPreventsFire(t *testing.T) {
38	clock := NewManualClock(time.Unix(0, 0))
39	timer := clock.NewTimer(5 * time.Millisecond)
40	if !timer.Stop() {
41		t.Fatal("first Stop = false, want true")
42	}
43	clock.Advance(10 * time.Millisecond)
44	expectNoFire(t, timer)
45	if timer.Stop() {
46		t.Fatal("second Stop = true, want false")
47	}
48}
49
50func TestManualClockResetRearmsAbsoluteDeadline(t *testing.T) {
51	start := time.Unix(0, 0)
52	clock := NewManualClock(start)
53	timer := clock.NewTimer(5 * time.Millisecond)
54	clock.Advance(5 * time.Millisecond)
55	expectFire(t, timer, start.Add(5*time.Millisecond))
56
57	timer.ResetAt(start.Add(8 * time.Millisecond))
58	expectNoFire(t, timer)
59	clock.Advance(3 * time.Millisecond)
60	expectFire(t, timer, start.Add(8*time.Millisecond))
61}
62
63func TestManualClockPastDeadlineFiresImmediately(t *testing.T) {
64	start := time.Unix(0, 0)
65	clock := NewManualClock(start)
66	timer := clock.NewTimer(0)
67	expectFire(t, timer, start)
68}
69
70func TestManualClockAdvancePanicsOnNegativeDuration(t *testing.T) {
71	clock := NewManualClock(time.Unix(0, 0))
72	defer func() {
73		if recover() == nil {
74			t.Fatal("Advance(-1) did not panic")
75		}
76	}()
77	clock.Advance(-time.Nanosecond)
78}
79
80func expectFire(t *testing.T, timer Timer, want time.Time) {
81	t.Helper()
82	select {
83	case got := <-timer.C():
84		if !got.Equal(want) {
85			t.Fatalf("timer fired at %s, want %s", got, want)
86		}
87	default:
88		t.Fatalf("timer did not fire, want %s", want)
89	}
90}
91
92func expectNoFire(t *testing.T, timer Timer) {
93	t.Helper()
94	select {
95	case got := <-timer.C():
96		t.Fatalf("timer fired at %s, want no fire", got)
97	default:
98	}
99}

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