check / check (push) Waiting to run
A blob upload that failed, such as one cut off by a lost connection, ended the backup at once. It is now tried again from the start of the blob up to five times, 3 seconds apart, with a warning before each retry; an interrupt still stops it at once. The panic in the report, "close of closed channel" from the progress reporter, was already fixed on next by the commit for issue 253; a test now covers a failing upload with the progress reporter on. Model: opus-5-5
125 lines
3.4 KiB
Go
125 lines
3.4 KiB
Go
package vaultik_test
|
|
|
|
import (
|
|
"context"
|
|
"maps"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/require"
|
|
"sneak.berlin/go/vaultik/internal/config"
|
|
"sneak.berlin/go/vaultik/internal/database"
|
|
"sneak.berlin/go/vaultik/internal/log"
|
|
"sneak.berlin/go/vaultik/internal/storage"
|
|
"sneak.berlin/go/vaultik/internal/storage/faultstore"
|
|
"sneak.berlin/go/vaultik/internal/vaultik"
|
|
)
|
|
|
|
// A backup without --cron runs the progress reporter while one scanner
|
|
// scans each path of the snapshot in turn. See
|
|
// https://git.eeqj.de/sneak/vaultik/issues/253.
|
|
func TestBackupWithoutCronOfTwoPathSnapshotRestoresBothPaths(t *testing.T) {
|
|
log.Initialize(log.Config{})
|
|
t.Parallel()
|
|
|
|
const snapshotName = "data"
|
|
|
|
fs := afero.NewOsFs()
|
|
tempDir := t.TempDir()
|
|
firstDir := filepath.Join(tempDir, "first")
|
|
secondDir := filepath.Join(tempDir, "second")
|
|
storeDir := t.TempDir()
|
|
restoreDir := filepath.Join(tempDir, "restored")
|
|
dbPath := filepath.Join(tempDir, "index.sqlite")
|
|
|
|
ctx := context.Background()
|
|
files := writeFaultSourceTree(t, fs, firstDir)
|
|
maps.Copy(files, writeFaultSourceTree(t, fs, secondDir))
|
|
|
|
cfg := faultTestConfig()
|
|
cfg.IndexPath = dbPath
|
|
cfg.ChunkSize = config.Size(faultChunkSize)
|
|
cfg.Snapshots = map[string]config.SnapshotConfig{
|
|
snapshotName: {Paths: []string{firstDir, secondDir}},
|
|
}
|
|
|
|
store, err := storage.NewFileStorer(storeDir)
|
|
require.NoError(t, err)
|
|
|
|
db, err := database.New(ctx, dbPath)
|
|
require.NoError(t, err)
|
|
|
|
repos := database.NewRepositories(db)
|
|
v := newBackupVaultik(ctx, cfg, store, repos, db, fs)
|
|
|
|
require.NoError(t, v.CreateSnapshot(&vaultik.SnapshotCreateOptions{
|
|
Snapshots: []string{snapshotName},
|
|
}))
|
|
|
|
id := localSnapshotID(ctx, t, repos, snapshotName)
|
|
require.NoError(t, db.Close())
|
|
|
|
reader := newReaderVaultik(ctx, cfg, store, nil, fs)
|
|
require.NoError(t, reader.Restore(&vaultik.RestoreOptions{
|
|
SnapshotID: id,
|
|
TargetDir: restoreDir,
|
|
Verify: true,
|
|
}))
|
|
|
|
assertRestoredTree(t, fs, restoreDir, files)
|
|
}
|
|
|
|
// A backup without --cron whose blob uploads keep failing stops with the
|
|
// upload's error, and stops the progress reporter once. See
|
|
// https://git.eeqj.de/sneak/vaultik/issues/476.
|
|
//
|
|
//nolint:paralleltest // installs the global logger via log.Initialize
|
|
func TestBackupWithoutCronStopsWithBlobUploadError(t *testing.T) {
|
|
log.Initialize(log.Config{})
|
|
|
|
const snapshotName = "data"
|
|
|
|
fs := afero.NewOsFs()
|
|
tempDir := t.TempDir()
|
|
firstDir := filepath.Join(tempDir, "first")
|
|
secondDir := filepath.Join(tempDir, "second")
|
|
dbPath := filepath.Join(tempDir, "index.sqlite")
|
|
|
|
ctx := context.Background()
|
|
|
|
writeFaultSourceTree(t, fs, firstDir)
|
|
writeFaultSourceTree(t, fs, secondDir)
|
|
|
|
cfg := faultTestConfig()
|
|
cfg.IndexPath = dbPath
|
|
cfg.ChunkSize = config.Size(faultChunkSize)
|
|
cfg.Snapshots = map[string]config.SnapshotConfig{
|
|
snapshotName: {Paths: []string{firstDir, secondDir}},
|
|
}
|
|
|
|
inner, err := storage.NewFileStorer(t.TempDir())
|
|
require.NoError(t, err)
|
|
|
|
store := faultstore.New(inner)
|
|
store.OnPut = func(key string) faultstore.PutAction {
|
|
if strings.HasPrefix(key, "blobs/") {
|
|
return faultstore.PutFail
|
|
}
|
|
|
|
return faultstore.PutNormal
|
|
}
|
|
|
|
db, err := database.New(ctx, dbPath)
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() { _ = db.Close() })
|
|
|
|
v := newBackupVaultik(ctx, cfg, store, database.NewRepositories(db), db, fs)
|
|
|
|
err = v.CreateSnapshot(&vaultik.SnapshotCreateOptions{
|
|
Snapshots: []string{snapshotName},
|
|
})
|
|
require.ErrorIs(t, err, faultstore.ErrInjectedUpload)
|
|
}
|