Skip to content

Commit

Permalink
core.fsyncmethod: tests for batch mode
Browse files Browse the repository at this point in the history
Add test cases to exercise batch mode for:
 * 'git add'
 * 'git stash'
 * 'git update-index'
 * 'git unpack-objects'

These tests ensure that the added data winds up in the object database.

In this change we introduce a new test helper lib-unique-files.sh. The
goal of this library is to create a tree of files that have different
oids from any other files that may have been created in the current test
repo. This helps us avoid missing validation of an object being added due
to it already being in the repo.

Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
  • Loading branch information
neerajsi-msft committed Jan 18, 2022
1 parent 0586a7b commit 7e9749a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 11 deletions.
36 changes: 36 additions & 0 deletions t/lib-unique-files.sh
@@ -0,0 +1,36 @@
# Helper to create files with unique contents


# Create multiple files with unique contents. Takes the number of
# directories, the number of files in each directory, and the base
# directory.
#
# test_create_unique_files 2 3 my_dir -- Creates 2 directories with 3 files
# each in my_dir, all with unique
# contents.

test_create_unique_files() {
test "$#" -ne 3 && BUG "3 param"

local dirs=$1
local files=$2
local basedir=$3
local counter=0
test_tick
local basedata=$test_tick


rm -rf $basedir

for i in $(test_seq $dirs)
do
local dir=$basedir/dir$i

mkdir -p "$dir"
for j in $(test_seq $files)
do
counter=$((counter + 1))
echo "$basedata.$counter" >"$dir/file$j.txt"
done
done
}
22 changes: 22 additions & 0 deletions t/t3700-add.sh
Expand Up @@ -8,6 +8,8 @@ test_description='Test of git add, including the -- option.'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

. $TEST_DIRECTORY/lib-unique-files.sh

# Test the file mode "$1" of the file "$2" in the index.
test_mode_in_index () {
case "$(git ls-files -s "$2")" in
Expand All @@ -34,6 +36,26 @@ test_expect_success \
'Test that "git add -- -q" works' \
'touch -- -q && git add -- -q'

BATCH_CONFIGURATION='core.fsync=default,loose-object -c core.fsyncmethod=batch'

test_expect_success 'git add: core.fsyncmethod=batch' "
test_create_unique_files 2 4 fsync-files &&
git -c $BATCH_CONFIGURATION add -- ./fsync-files/ &&
rm -f fsynced_files &&
git ls-files --stage fsync-files/ > fsynced_files &&
test_line_count = 8 fsynced_files &&
awk -- '{print \$2}' fsynced_files | xargs -n1 git cat-file -e
"

test_expect_success 'git update-index: core.fsyncmethod=batch' "
test_create_unique_files 2 4 fsync-files2 &&
find fsync-files2 ! -type d -print | xargs git -c $BATCH_CONFIGURATION update-index --add -- &&
rm -f fsynced_files2 &&
git ls-files --stage fsync-files2/ > fsynced_files2 &&
test_line_count = 8 fsynced_files2 &&
awk -- '{print \$2}' fsynced_files2 | xargs -n1 git cat-file -e
"

test_expect_success \
'git add: Test that executable bit is not used if core.filemode=0' \
'git config core.filemode 0 &&
Expand Down
16 changes: 16 additions & 0 deletions t/t3903-stash.sh
Expand Up @@ -9,6 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME

. ./test-lib.sh
. $TEST_DIRECTORY/lib-unique-files.sh

test_expect_success 'usage on cmd and subcommand invalid option' '
test_expect_code 129 git stash --invalid-option 2>usage &&
Expand Down Expand Up @@ -1323,6 +1324,21 @@ test_expect_success 'stash handles skip-worktree entries nicely' '
git rev-parse --verify refs/stash:A.t
'

BATCH_CONFIGURATION='core.fsync=default,loose-object -c core.fsyncmethod=batch'

test_expect_success 'stash with core.fsyncmethod=batch' "
test_create_unique_files 2 4 fsync-files &&
git -c $BATCH_CONFIGURATION stash push -u -- ./fsync-files/ &&
rm -f fsynced_files &&
# The files were untracked, so use the third parent,
# which contains the untracked files
git ls-tree -r stash^3 -- ./fsync-files/ > fsynced_files &&
test_line_count = 8 fsynced_files &&
awk -- '{print \$3}' fsynced_files | xargs -n1 git cat-file -e
"


test_expect_success 'stash -c stash.useBuiltin=false warning ' '
expected="stash.useBuiltin support has been removed" &&
Expand Down
32 changes: 21 additions & 11 deletions t/t5300-pack-object.sh
Expand Up @@ -162,23 +162,25 @@ test_expect_success 'pack-objects with bogus arguments' '

check_unpack () {
test_when_finished "rm -rf git2" &&
git init --bare git2 &&
git -C git2 unpack-objects -n <"$1".pack &&
git -C git2 unpack-objects <"$1".pack &&
(cd .git && find objects -type f -print) |
while read path
do
cmp git2/$path .git/$path || {
echo $path differs.
return 1
}
done
git $2 init --bare git2 &&
(
git $2 -C git2 unpack-objects -n <"$1".pack &&
git $2 -C git2 unpack-objects <"$1".pack &&
git $2 -C git2 cat-file --batch-check="%(objectname)"
) <obj-list >current &&
cmp obj-list current
}

test_expect_success 'unpack without delta' '
check_unpack test-1-${packname_1}
'

BATCH_CONFIGURATION='core.fsync=default,loose-object -c core.fsyncmethod=batch'

test_expect_success 'unpack without delta (core.fsyncmethod=batch)' '
check_unpack test-1-${packname_1} "$BATCH_CONFIGURATION"
'

test_expect_success 'pack with REF_DELTA' '
packname_2=$(git pack-objects --progress test-2 <obj-list 2>stderr) &&
check_deltas stderr -gt 0
Expand All @@ -188,6 +190,10 @@ test_expect_success 'unpack with REF_DELTA' '
check_unpack test-2-${packname_2}
'

test_expect_success 'unpack with REF_DELTA (core.fsyncobjectfiles=batch)' '
check_unpack test-2-${packname_2} "$BATCH_CONFIGURATION"
'

test_expect_success 'pack with OFS_DELTA' '
packname_3=$(git pack-objects --progress --delta-base-offset test-3 \
<obj-list 2>stderr) &&
Expand All @@ -198,6 +204,10 @@ test_expect_success 'unpack with OFS_DELTA' '
check_unpack test-3-${packname_3}
'

test_expect_success 'unpack with OFS_DELTA (core.fsyncobjectfiles=batch)' '
check_unpack test-3-${packname_3} "$BATCH_CONFIGURATION"
'

test_expect_success 'compare delta flavors' '
perl -e '\''
defined($_ = -s $_) or die for @ARGV;
Expand Down

0 comments on commit 7e9749a

Please sign in to comment.