Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update migration sharness tests for new migrations #8053

Merged
merged 5 commits into from
Apr 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions test/sharness/t0066-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,47 @@ test_description="Test migrations auto update prompt"

test_init_ipfs

MIGRATION_START=7
IPFS_REPO_VER=$(<.ipfs/version)

# Generate mock migration binaries
gen_mock_migrations() {
mkdir bin
i=$((MIGRATION_START))
until [ $i -ge $IPFS_REPO_VER ]
do
j=$((i+1))
echo "#!/bin/bash" > bin/fs-repo-${i}-to-${j}
echo "echo fake applying ${i}-to-${j} repo migration" >> bin/fs-repo-${i}-to-${j}
chmod +x bin/fs-repo-${i}-to-${j}
((i++))
done
}

# Check for expected output from each migration
check_migration_output() {
out_file="$1"
i=$((MIGRATION_START))
until [ $i -ge $IPFS_REPO_VER ]
do
j=$((i+1))
grep "applying ${i}-to-${j} repo migration" "$out_file" > /dev/null
((i++))
done
}

# Create fake migration binaries instead of letting ipfs download from network
# To test downloading and running actual binaries, comment out this test.
Copy link
Contributor

@aschmahmann aschmahmann Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We weren't testing real binaries here before, right? So this is just a heads up for developers/testers.

Not that it's strictly necessary (as it can cause CI flakiness, slow downs, etc.), but do we happen to already have any integration tests that handle the end-to-end workflow here?

Copy link
Contributor Author

@gammazero gammazero Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, before we were also testing a fake migration binary (mocked fs-repo-migrations). No that we do not have one fs-repo-migration, but have separate migration executables, I make fake versions of those now.

The actual migrations are tested in fs-repo-migrations sharness tests. This part tests that the go-ipfs will actually run the migrations.

The part that is missing from a complete end-to-end test is testing go-ipfs downloading migrations from the network.

test_expect_success "setup mock migrations" '
mkdir bin &&
echo "#!/bin/bash" > bin/fs-repo-migrations &&
echo "echo 5" >> bin/fs-repo-migrations &&
chmod +x bin/fs-repo-migrations &&
export PATH="$(pwd)/bin":$PATH
gen_mock_migrations &&
find bin -name "fs-repo-*-to-*" | wc -l > mock_count &&
echo $((IPFS_REPO_VER-MIGRATION_START)) > expect_mock_count &&
export PATH="$(pwd)/bin":$PATH &&
test_cmp mock_count expect_mock_count
'

test_expect_success "manually reset repo version to 3" '
echo "3" > "$IPFS_PATH"/version
test_expect_success "manually reset repo version to $MIGRATION_START" '
echo "$MIGRATION_START" > "$IPFS_PATH"/version
'

test_expect_success "ipfs daemon --migrate=false fails" '
Expand All @@ -30,13 +61,17 @@ test_expect_success "output looks good" '
grep "Please get fs-repo-migrations from https://dist.ipfs.io" false_out
'

# The migrations will succeed, but the daemon will still exit with 1 because
# the fake migrations do not update the repo version number.
#
# If run with real migrations, the daemon continues running and must be killed.
test_expect_success "ipfs daemon --migrate=true runs migration" '
test_expect_code 1 ipfs daemon --migrate=true > true_out
'

test_expect_failure "output looks good" '
grep "Running: " true_out > /dev/null &&
grep "Success: fs-repo has been migrated to version 5." true_out > /dev/null
test_expect_success "output looks good" '
check_migration_output true_out &&
grep "Success: fs-repo migrated to version $IPFS_REPO_VER" true_out > /dev/null
'

test_expect_success "'ipfs daemon' prompts to auto migrate" '
Expand Down