]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5351-unpack-large-objects.sh
leak tests: don't skip some tests under SANITIZE=leak
[thirdparty/git.git] / t / t5351-unpack-large-objects.sh
CommitLineData
a1bf5ca2
HX
1#!/bin/sh
2#
3# Copyright (c) 2022 Han Xin
4#
5
6test_description='git unpack-objects with large objects'
7
8. ./test-lib.sh
9
10prepare_dest () {
11 test_when_finished "rm -rf dest.git" &&
aaf81223
HX
12 git init --bare dest.git &&
13 git -C dest.git config core.bigFileThreshold "$1"
a1bf5ca2
HX
14}
15
16test_expect_success "create large objects (1.5 MB) and PACK" '
17 test-tool genrandom foo 1500000 >big-blob &&
18 test_commit --append foo big-blob &&
19 test-tool genrandom bar 1500000 >big-blob &&
20 test_commit --append bar big-blob &&
aaf81223
HX
21 PACK=$(echo HEAD | git pack-objects --revs pack) &&
22 git verify-pack -v pack-$PACK.pack >out &&
23 sed -n -e "s/^\([0-9a-f][0-9a-f]*\).*\(commit\|tree\|blob\).*/\1/p" \
24 <out >obj-list
a1bf5ca2
HX
25'
26
27test_expect_success 'set memory limitation to 1MB' '
28 GIT_ALLOC_LIMIT=1m &&
29 export GIT_ALLOC_LIMIT
30'
31
32test_expect_success 'unpack-objects failed under memory limitation' '
aaf81223 33 prepare_dest 2m &&
a1bf5ca2
HX
34 test_must_fail git -C dest.git unpack-objects <pack-$PACK.pack 2>err &&
35 grep "fatal: attempting to allocate" err
36'
37
38test_expect_success 'unpack-objects works with memory limitation in dry-run mode' '
aaf81223 39 prepare_dest 2m &&
a1bf5ca2
HX
40 git -C dest.git unpack-objects -n <pack-$PACK.pack &&
41 test_stdout_line_count = 0 find dest.git/objects -type f &&
42 test_dir_is_empty dest.git/objects/pack
43'
44
aaf81223
HX
45test_expect_success 'unpack big object in stream' '
46 prepare_dest 1m &&
47 git -C dest.git unpack-objects <pack-$PACK.pack &&
48 test_dir_is_empty dest.git/objects/pack
49'
50
51BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
52
53test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' '
54 prepare_dest 1m &&
55 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
56 git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack &&
57 grep fsync/hardware-flush trace2.txt &&
58 test_dir_is_empty dest.git/objects/pack &&
59 git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current &&
60 cmp obj-list current
61'
62
63test_expect_success 'do not unpack existing large objects' '
64 prepare_dest 1m &&
65 git -C dest.git index-pack --stdin <pack-$PACK.pack &&
66 git -C dest.git unpack-objects <pack-$PACK.pack &&
67
68 # The destination came up with the exact same pack...
69 DEST_PACK=$(echo dest.git/objects/pack/pack-*.pack) &&
70 test_cmp pack-$PACK.pack $DEST_PACK &&
71
72 # ...and wrote no loose objects
73 test_stdout_line_count = 0 find dest.git/objects -type f ! -name "pack-*"
74'
75
a1bf5ca2 76test_done