connection_concurrency_test.go RawHistoryFolder

1package sqlite
2
3import (
4	"context"
5	"errors"
6	"os"
7	"path/filepath"
8	"sync"
9	"testing"
10	"time"
11
12	"github.com/stretchr/testify/require"
13)
14
15func TestRetryPragmaHonorsCancellation(t *testing.T) {
16	ctx, cancel := context.WithCancel(context.Background())
17	cancel()
18	start := time.Now()
19	err := retryPragma(ctx, func() error { return errors.New("database is locked") })
20	require.ErrorIs(t, err, context.Canceled)
21	require.Less(t, time.Since(start), lockRetryInterval)
22}
23
24func TestLockDatabaseStartupTruncatesStaleContents(t *testing.T) {
25	path := filepath.Join(t.TempDir(), "startup.lock")
26	require.NoError(t, os.WriteFile(path, []byte("stale"), 0o600))
27	lock, err := lockDatabaseStartup(context.Background(), path)
28	require.NoError(t, err)
29	require.NoError(t, lock.Close())
30	info, err := os.Stat(path)
31	require.NoError(t, err)
32	require.Zero(t, info.Size())
33}
34
35func TestNewConnectionUsesWAL(t *testing.T) {
36	db, err := NewConnection(context.Background(), filepath.Join(t.TempDir(), "wal.db"))
37	require.NoError(t, err)
38	defer db.Close()
39	var mode string
40	require.NoError(t, db.QueryRow("PRAGMA journal_mode").Scan(&mode))
41	require.Equal(t, "wal", mode)
42}
43
44func TestNewConnectionConcurrentFirstOpen(t *testing.T) {
45	dbPath := filepath.Join(t.TempDir(), "shared.db")
46	const openers = 8
47	var wg sync.WaitGroup
48	openErrors := make(chan error, openers)
49	for range openers {
50		wg.Add(1)
51		go func() {
52			defer wg.Done()
53			db, err := NewConnection(context.Background(), dbPath)
54			if err == nil {
55				err = db.Close()
56			}
57			openErrors <- err
58		}()
59	}
60	wg.Wait()
61	close(openErrors)
62	for err := range openErrors {
63		require.NoError(t, err)
64	}
65}

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 8

Tags 42

↑↓ moveenter openesc close