detached e8cafa1

test(daemon): cover concurrent MRU touches

commit
e8cafa154672076d6a876dcafe48c15c2ae2ecaa
author
brice · · 2026-07-05 08:17 UTC
parent
467a998
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +50 -0
M internal/usecase/daemon/session_test.go +50 -0
@@ -5,6 +5,7 @@ import (
55 "io"
66 "log/slog"
77 "sync"
8+ "sync/atomic"
89 "testing"
910 "time"
1011
@@ -659,6 +660,55 @@ func TestDaemonLoadsPersistedSessionsAsStopped(t *testing.T) {
659660 require.Equal(t, stoppedSession{name: "work", cwd: "/tmp/work", createdAt: 7}, stopped)
660661 }
661662
663+func TestTouchMRUConcurrentUpdatesRemainMonotonic(t *testing.T) {
664+ d := &Daemon{}
665+ sess := &session{}
666+ const goroutines = 16
667+ const iterations = 1000
668+ start := make(chan struct{})
669+ done := make(chan struct{})
670+ var decreased atomic.Bool
671+ var wg sync.WaitGroup
672+ var observer sync.WaitGroup
673+
674+ observer.Add(1)
675+ go func() {
676+ defer observer.Done()
677+ previous := sess.mruAt.Load()
678+ for {
679+ select {
680+ case <-done:
681+ return
682+ default:
683+ }
684+ current := sess.mruAt.Load()
685+ if current < previous {
686+ decreased.Store(true)
687+ return
688+ }
689+ previous = current
690+ }
691+ }()
692+
693+ for range goroutines {
694+ wg.Add(1)
695+ go func() {
696+ defer wg.Done()
697+ <-start
698+ for range iterations {
699+ d.touchMRU(sess)
700+ }
701+ }()
702+ }
703+ close(start)
704+ wg.Wait()
705+ close(done)
706+ observer.Wait()
707+
708+ require.False(t, decreased.Load())
709+ require.Equal(t, d.mruSeq.Load(), sess.mruAt.Load())
710+}
711+
662712 func TestCreateRenameKillPersistenceLifecycle(t *testing.T) {
663713 sz := domain.Size{Cols: 80, Rows: 24}
664714 p, release := newBlockingPTY(t)
@@ -5,6 +5,7 @@ import (
5 "io"5 "io"
6 "log/slog"6 "log/slog"
7 "sync"7 "sync"
8+ "sync/atomic"
8 "testing"9 "testing"
9 "time"10 "time"
10 11
@@ -659,6 +660,55 @@ func TestDaemonLoadsPersistedSessionsAsStopped(t *testing.T) {
659 require.Equal(t, stoppedSession{name: "work", cwd: "/tmp/work", createdAt: 7}, stopped)660 require.Equal(t, stoppedSession{name: "work", cwd: "/tmp/work", createdAt: 7}, stopped)
660 }661 }
661 662
663+func TestTouchMRUConcurrentUpdatesRemainMonotonic(t *testing.T) {
664+ d := &Daemon{}
665+ sess := &session{}
666+ const goroutines = 16
667+ const iterations = 1000
668+ start := make(chan struct{})
669+ done := make(chan struct{})
670+ var decreased atomic.Bool
671+ var wg sync.WaitGroup
672+ var observer sync.WaitGroup
673+
674+ observer.Add(1)
675+ go func() {
676+ defer observer.Done()
677+ previous := sess.mruAt.Load()
678+ for {
679+ select {
680+ case <-done:
681+ return
682+ default:
683+ }
684+ current := sess.mruAt.Load()
685+ if current < previous {
686+ decreased.Store(true)
687+ return
688+ }
689+ previous = current
690+ }
691+ }()
692+
693+ for range goroutines {
694+ wg.Add(1)
695+ go func() {
696+ defer wg.Done()
697+ <-start
698+ for range iterations {
699+ d.touchMRU(sess)
700+ }
701+ }()
702+ }
703+ close(start)
704+ wg.Wait()
705+ close(done)
706+ observer.Wait()
707+
708+ require.False(t, decreased.Load())
709+ require.Equal(t, d.mruSeq.Load(), sess.mruAt.Load())
710+}
711+
662 func TestCreateRenameKillPersistenceLifecycle(t *testing.T) {712 func TestCreateRenameKillPersistenceLifecycle(t *testing.T) {
663 sz := domain.Size{Cols: 80, Rows: 24}713 sz := domain.Size{Cols: 80, Rows: 24}
664 p, release := newBlockingPTY(t)714 p, release := newBlockingPTY(t)

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