mirror of
https://github.com/octoleo/restic.git
synced 2024-12-28 04:56:04 +00:00
120ccc8754
Previously, SaveAndEncrypt would assemble blobs into packs and either return immediately if the pack is not yet full or upload the pack file otherwise. The upload will block the current goroutine until it finishes. Now, the upload is done using separate goroutines. This requires changes to the error handling. As uploads are no longer tied to a SaveAndEncrypt call, failed uploads are signaled using an errgroup. To count the uploaded amount of data, the pack header overhead is no longer returned by `packer.Finalize` but rather by `packer.HeaderOverhead`. This helper method is necessary to continue returning the pack header overhead directly to the responsible call to `repository.SaveBlob`. Without the method this would not be possible, as packs are finalized asynchronously.
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
//go:build go1.18
|
|
// +build go1.18
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/restic/restic/internal/backend/mem"
|
|
"github.com/restic/restic/internal/restic"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
// Test saving a blob and loading it again, with varying buffer sizes.
|
|
// Also a regression test for #3783.
|
|
func FuzzSaveLoadBlob(f *testing.F) {
|
|
f.Fuzz(func(t *testing.T, blob []byte, buflen uint) {
|
|
if buflen > 64<<20 {
|
|
// Don't allocate enormous buffers. We're not testing the allocator.
|
|
t.Skip()
|
|
}
|
|
|
|
id := restic.Hash(blob)
|
|
repo, _ := TestRepositoryWithBackend(t, mem.New(), 2)
|
|
|
|
var wg errgroup.Group
|
|
repo.StartPackUploader(context.TODO(), &wg)
|
|
|
|
_, _, _, err := repo.SaveBlob(context.TODO(), restic.DataBlob, blob, id, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = repo.Flush(context.TODO())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
buf, err := repo.LoadBlob(context.TODO(), restic.DataBlob, id, make([]byte, buflen))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if restic.Hash(buf) != id {
|
|
t.Fatal("mismatch")
|
|
}
|
|
})
|
|
}
|