MCPcopy
hub / github.com/perkeep/perkeep / TestPackerBoundarySplits

Function TestPackerBoundarySplits

pkg/blobserver/blobpacked/blobpacked_test.go:970–1092  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

968}
969
970func TestPackerBoundarySplits(t *testing.T) {
971 if testing.Short() {
972 t.Skip("skipping slow test")
973 }
974 // Test a file of three chunk sizes, totalling near the 16 MB
975 // boundary:
976 // - 1st chunk is 6 MB. ("blobA")
977 // - 2nd chunk is 6 MB. ("blobB")
978 // - 3rd chunk ("blobC") is binary-searched (up to 4MB) to find
979 // which size causes the packer to write two zip files.
980
981 // During the test we set zip overhead boundaries to 0, to
982 // force the test to into its pathological misprediction code paths,
983 // where it needs to back up and rewrite the zip with one part less.
984 // That's why the test starts with two zip files: so there's at
985 // least one that can be removed to make room.
986 defer setIntTemporarily(&zipPerEntryOverhead, 0)()
987
988 const sizeAB = 12 << 20
989 const maxBlobSize = 16 << 20
990 bytesAB := randBytes(sizeAB)
991 blobA := &test.Blob{Contents: string(bytesAB[:sizeAB/2])}
992 blobB := &test.Blob{Contents: string(bytesAB[sizeAB/2:])}
993 refA := blobA.BlobRef()
994 refB := blobB.BlobRef()
995 bytesCFull := randBytes(maxBlobSize - sizeAB) // will be sliced down
996
997 // Mechanism to verify we hit the back-up code path:
998 var (
999 mu sync.Mutex
1000 sawTruncate blob.Ref
1001 stoppedBeforeOverflow bool
1002 )
1003 testHookSawTruncate = func(after blob.Ref) {
1004 if after != refB {
1005 t.Errorf("unexpected truncate point %v", after)
1006 }
1007 mu.Lock()
1008 defer mu.Unlock()
1009 sawTruncate = after
1010 }
1011 testHookStopBeforeOverflowing = func() {
1012 mu.Lock()
1013 defer mu.Unlock()
1014 stoppedBeforeOverflow = true
1015 }
1016 defer func() {
1017 testHookSawTruncate = nil
1018 testHookStopBeforeOverflowing = nil
1019 }()
1020
1021 generatesTwoZips := func(sizeC int) (ret bool) {
1022 large := new(test.Fetcher)
1023 s := &storage{
1024 small: new(test.Fetcher),
1025 large: large,
1026 meta: sorted.NewMemoryKeyValue(),
1027 log: test.NewLogger(t, "blobpacked: ",

Callers

nothing calls this directly

Calls 15

BlobRefMethod · 0.95
initMethod · 0.95
MustUploadMethod · 0.95
ReceiveBlobMethod · 0.95
NewMemoryKeyValueFunction · 0.92
NewLoggerFunction · 0.92
NewHashFunction · 0.92
RefFromHashFunction · 0.92
NewFileMapFunction · 0.92
setIntTemporarilyFunction · 0.85
randBytesFunction · 0.85
LockMethod · 0.80

Tested by

no test coverage detected