From fe028a3c53d197cd2d7cdc440ff30d97e7fe4bb9 Mon Sep 17 00:00:00 2001 From: gammazero Date: Mon, 5 Apr 2021 18:58:11 -0700 Subject: [PATCH 1/5] Update migration sharness tests for new migrations With the new migrations, go-ipfs no longer uses fs-repo-migrations to do repo migrations, and was downloading real migration binaries from the network and running them. This caused failure, but was not caught because the test was expecting `ipfs daemon --migrate` to fail for other reasons. This PR fixes the migration tests by creating the appropriate fake migration binaries in the PATH so that those get run and avoid downloading the real ones. This also fixes a test that was previously marked broken. --- test/sharness/t0066-migration.sh | 39 ++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/test/sharness/t0066-migration.sh b/test/sharness/t0066-migration.sh index 5e1301befb7..56e2c94a0c2 100755 --- a/test/sharness/t0066-migration.sh +++ b/test/sharness/t0066-migration.sh @@ -10,16 +10,27 @@ test_description="Test migrations auto update prompt" test_init_ipfs +# Create fake migration binaries instead of letting ipfs download from network +# To test downloading and running actual binaries, comment out this test. 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 && + echo "#!/bin/bash" > bin/fs-repo-7-to-8 && + echo "echo fake applying 7-to-8 repo migration" >> bin/fs-repo-7-to-8 && + chmod +x bin/fs-repo-7-to-8 && + echo "#!/bin/bash" > bin/fs-repo-8-to-9 && + echo "echo fake applying 8-to-9 repo migration" >> bin/fs-repo-8-to-9 && + chmod +x bin/fs-repo-8-to-9 && + echo "#!/bin/bash" > bin/fs-repo-9-to-10 && + echo "echo fake applying 9-to-10 repo migration" >> bin/fs-repo-9-to-10 && + chmod +x bin/fs-repo-9-to-10 && + echo "#!/bin/bash" > bin/fs-repo-10-to-11 && + echo "echo fake applying 10-to-11 repo migration" >> bin/fs-repo-10-to-11 && + chmod +x bin/fs-repo-10-to-11 && export PATH="$(pwd)/bin":$PATH ' -test_expect_success "manually reset repo version to 3" ' - echo "3" > "$IPFS_PATH"/version +test_expect_success "manually reset repo version to 7" ' + echo "7" > "$IPFS_PATH"/version ' test_expect_success "ipfs daemon --migrate=false fails" ' @@ -30,17 +41,25 @@ 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_code 1 ipfs daemon --migrate=true > true_out 2>&1 ' -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" ' + grep "applying 7-to-8 repo migration" true_out > /dev/null && + grep "applying 8-to-9 repo migration" true_out > /dev/null && + grep "applying 9-to-10 repo migration" true_out > /dev/null && + grep "applying 10-to-11 repo migration" true_out > /dev/null && + grep "Success: fs-repo migrated to version 11" true_out > /dev/null ' +# Daemon exits with 1 after the prompt gets "n" when asking to migrate. test_expect_success "'ipfs daemon' prompts to auto migrate" ' - test_expect_code 1 ipfs daemon > daemon_out 2> daemon_err + test_expect_code 1 bash -c "echo n | ipfs daemon > daemon_out 2> daemon_err" ' test_expect_success "output looks good" ' From 3ef7d9d23b2969b11e06091c7ae9abb28269fc59 Mon Sep 17 00:00:00 2001 From: gammazero Date: Wed, 14 Apr 2021 11:39:11 -0700 Subject: [PATCH 2/5] revert unneeded change --- test/sharness/t0066-migration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sharness/t0066-migration.sh b/test/sharness/t0066-migration.sh index 56e2c94a0c2..f1381f2c7cc 100755 --- a/test/sharness/t0066-migration.sh +++ b/test/sharness/t0066-migration.sh @@ -59,7 +59,7 @@ test_expect_success "output looks good" ' # Daemon exits with 1 after the prompt gets "n" when asking to migrate. test_expect_success "'ipfs daemon' prompts to auto migrate" ' - test_expect_code 1 bash -c "echo n | ipfs daemon > daemon_out 2> daemon_err" + test_expect_code 1 ipfs daemon > daemon_out 2> daemon_err ' test_expect_success "output looks good" ' From 56cb4b33d66869c82344cbd0038a6844274a94e4 Mon Sep 17 00:00:00 2001 From: gammazero Date: Wed, 14 Apr 2021 15:19:20 -0700 Subject: [PATCH 3/5] review change --- test/sharness/t0066-migration.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/sharness/t0066-migration.sh b/test/sharness/t0066-migration.sh index f1381f2c7cc..d4aa892024b 100755 --- a/test/sharness/t0066-migration.sh +++ b/test/sharness/t0066-migration.sh @@ -57,7 +57,6 @@ test_expect_success "output looks good" ' grep "Success: fs-repo migrated to version 11" true_out > /dev/null ' -# Daemon exits with 1 after the prompt gets "n" when asking to migrate. test_expect_success "'ipfs daemon' prompts to auto migrate" ' test_expect_code 1 ipfs daemon > daemon_out 2> daemon_err ' From 66db9a1e66b3a0d9891d00dfda7f1cb9412e4878 Mon Sep 17 00:00:00 2001 From: gammazero Date: Thu, 15 Apr 2021 08:34:24 -0700 Subject: [PATCH 4/5] Rebase to fix test, and restore test to original form --- test/sharness/t0066-migration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sharness/t0066-migration.sh b/test/sharness/t0066-migration.sh index d4aa892024b..38d9da1b90c 100755 --- a/test/sharness/t0066-migration.sh +++ b/test/sharness/t0066-migration.sh @@ -46,7 +46,7 @@ test_expect_success "output looks good" ' # # 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 2>&1 + test_expect_code 1 ipfs daemon --migrate=true > true_out ' test_expect_success "output looks good" ' From 4dabe214cfd0d787bbc4277517eb9eb325bed6ec Mon Sep 17 00:00:00 2001 From: gammazero Date: Thu, 15 Apr 2021 11:03:53 -0700 Subject: [PATCH 5/5] Generate mock migration bins --- test/sharness/t0066-migration.sh | 59 ++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/test/sharness/t0066-migration.sh b/test/sharness/t0066-migration.sh index 38d9da1b90c..aa40fd8a468 100755 --- a/test/sharness/t0066-migration.sh +++ b/test/sharness/t0066-migration.sh @@ -10,27 +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. test_expect_success "setup mock migrations" ' - mkdir bin && - echo "#!/bin/bash" > bin/fs-repo-7-to-8 && - echo "echo fake applying 7-to-8 repo migration" >> bin/fs-repo-7-to-8 && - chmod +x bin/fs-repo-7-to-8 && - echo "#!/bin/bash" > bin/fs-repo-8-to-9 && - echo "echo fake applying 8-to-9 repo migration" >> bin/fs-repo-8-to-9 && - chmod +x bin/fs-repo-8-to-9 && - echo "#!/bin/bash" > bin/fs-repo-9-to-10 && - echo "echo fake applying 9-to-10 repo migration" >> bin/fs-repo-9-to-10 && - chmod +x bin/fs-repo-9-to-10 && - echo "#!/bin/bash" > bin/fs-repo-10-to-11 && - echo "echo fake applying 10-to-11 repo migration" >> bin/fs-repo-10-to-11 && - chmod +x bin/fs-repo-10-to-11 && - 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 7" ' - echo "7" > "$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" ' @@ -50,11 +70,8 @@ test_expect_success "ipfs daemon --migrate=true runs migration" ' ' test_expect_success "output looks good" ' - grep "applying 7-to-8 repo migration" true_out > /dev/null && - grep "applying 8-to-9 repo migration" true_out > /dev/null && - grep "applying 9-to-10 repo migration" true_out > /dev/null && - grep "applying 10-to-11 repo migration" true_out > /dev/null && - grep "Success: fs-repo migrated to version 11" true_out > /dev/null + 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" '