|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description="Test migration 3 to 4 with lots of objects" |
| 4 | + |
| 5 | +. lib/test-lib.sh |
| 6 | + |
| 7 | +# setup vars for tests |
| 8 | + |
| 9 | +export IPFS_DIST_PATH="/ipfs/QmUGSSMCcPTeLCyrjKdozh2XY9VUdJVYxA6LjyJjLPcXST" |
| 10 | + |
| 11 | +DEPTH=3 |
| 12 | +NBDIR=3 |
| 13 | +NBFILE=6 |
| 14 | +PINTOTAL=20 |
| 15 | + |
| 16 | +if test_have_prereq EXPENSIVE |
| 17 | +then |
| 18 | + DEPTH=6 |
| 19 | + NBDIR=7 |
| 20 | + NBFILE=10 |
| 21 | + PINTOTAL=2000 |
| 22 | +fi |
| 23 | + |
| 24 | +PINEACH=$(expr $PINTOTAL / 2) |
| 25 | + |
| 26 | +echo "DEPTH: $DEPTH" |
| 27 | +echo "NBDIR: $NBDIR" |
| 28 | +echo "NBFILE: $NBFILE" |
| 29 | +echo "PINTOTAL: $PINTOTAL" |
| 30 | +echo "PINEACH: $PINEACH" |
| 31 | + |
| 32 | +test_expect_success "start a docker container" ' |
| 33 | + DOCID=$(start_docker) |
| 34 | +' |
| 35 | + |
| 36 | +drun() { |
| 37 | + exec_docker "$DOCID" "$@" |
| 38 | +} |
| 39 | + |
| 40 | +test_docker_wait_for_file() { |
| 41 | + docid="$1" |
| 42 | + loops="$2" |
| 43 | + delay="$3" |
| 44 | + file="$4" |
| 45 | + fwaitc=0 |
| 46 | + while ! exec_docker "$docid" "test -f '$file'" |
| 47 | + do |
| 48 | + if test $fwaitc -ge $loops |
| 49 | + then |
| 50 | + echo "Error: timed out waiting for file: $file" |
| 51 | + return 1 |
| 52 | + fi |
| 53 | + |
| 54 | + go-sleep $delay |
| 55 | + fwaitc=$(expr $fwaitc + 1) |
| 56 | + done |
| 57 | +} |
| 58 | + |
| 59 | +test_install_version "v0.4.2" |
| 60 | + |
| 61 | +test_init_daemon "$DOCID" |
| 62 | + |
| 63 | +test_start_daemon "$DOCID" |
| 64 | + |
| 65 | +test_expect_success "make a couple files" ' |
| 66 | + drun "rm -rf manyfiles" && |
| 67 | + drun "$GUEST_RANDOM_FILES -depth=$DEPTH -dirs=$NBDIR -files=$NBFILE manyfiles" > filenames |
| 68 | +' |
| 69 | + |
| 70 | +test_expect_success "add a few files" ' |
| 71 | + drun "ipfs add -r -q manyfiles" | tee hashes |
| 72 | +' |
| 73 | + |
| 74 | +test_expect_success "unpin root so we can do things ourselves" ' |
| 75 | + drun "ipfs pin rm $(tail -n1 hashes)" |
| 76 | +' |
| 77 | + |
| 78 | +test_expect_success "select random subset to pin recursively and directly" ' |
| 79 | + sort -R hashes | head -n$PINTOTAL > topin && |
| 80 | + head -n$PINEACH topin > recurpins && |
| 81 | + tail -n$PINEACH topin > directpins |
| 82 | +' |
| 83 | + |
| 84 | +pin_hashes() { |
| 85 | + hashes_file="$1" |
| 86 | + opts="$2" |
| 87 | + for h in `cat $hashes_file`; do |
| 88 | + if ! drun "ipfs pin add $opts $h"; then |
| 89 | + return 1 |
| 90 | + fi |
| 91 | + done |
| 92 | +} |
| 93 | + |
| 94 | +test_expect_success "pin some objects recursively" ' |
| 95 | + pin_hashes recurpins |
| 96 | +' |
| 97 | + |
| 98 | +test_expect_success "pin some objects directly" ' |
| 99 | + pin_hashes directpins "-r=false" |
| 100 | +' |
| 101 | + |
| 102 | +test_expect_success "get full ref list" ' |
| 103 | + drun "ipfs refs local" | sort > start_refs |
| 104 | +' |
| 105 | + |
| 106 | +test_expect_success "get pin lists" ' |
| 107 | + drun "ipfs pin ls --type=recursive" | sort > start_rec_pins && |
| 108 | + drun "ipfs pin ls --type=direct" | sort > start_dir_pins && |
| 109 | + drun "ipfs pin ls --type=indirect" | sort > start_ind_pins |
| 110 | +' |
| 111 | + |
| 112 | +test_stop_daemon $DOCID |
| 113 | + |
| 114 | +test_install_version "v0.4.3-dev" |
| 115 | + |
| 116 | +test_start_daemon $DOCID |
| 117 | + |
| 118 | +test_expect_success "list all refs after migration" ' |
| 119 | + drun "ipfs refs local" | sort > after_refs |
| 120 | +' |
| 121 | + |
| 122 | +test_expect_success "list all pins after migration" ' |
| 123 | + drun "ipfs pin ls --type=recursive" | sort > after_rec_pins && |
| 124 | + drun "ipfs pin ls --type=direct" | sort > after_dir_pins && |
| 125 | + drun "ipfs pin ls --type=indirect" | sort > after_ind_pins |
| 126 | +' |
| 127 | + |
| 128 | +test_expect_success "refs look right" ' |
| 129 | + comm -23 start_refs after_refs > missing_refs && |
| 130 | + touch empty_refs_file && |
| 131 | + test_cmp missing_refs empty_refs_file |
| 132 | +' |
| 133 | + |
| 134 | +test_expect_success "pins all look the same" ' |
| 135 | + test_cmp start_rec_pins after_rec_pins && |
| 136 | + test_cmp start_dir_pins after_dir_pins && |
| 137 | + test_cmp start_ind_pins after_ind_pins |
| 138 | +' |
| 139 | + |
| 140 | +test_expect_success "manually compute gc set" ' |
| 141 | + cat after_rec_pins after_dir_pins after_ind_pins | sort > all_pinned |
| 142 | +' |
| 143 | + |
| 144 | +test_expect_success "run a gc" ' |
| 145 | + drun "ipfs repo gc" | sort > gc_out |
| 146 | +' |
| 147 | + |
| 148 | +test_expect_success "no pinned objects were gc'ed" ' |
| 149 | + comm -12 gc_out all_pinned > gced_pinned_objects && |
| 150 | + test_cmp empty_refs_file gced_pinned_objects |
| 151 | +' |
| 152 | + |
| 153 | +test_expect_success "list all pins after gc" ' |
| 154 | + drun "ipfs pin ls --type=recursive" | sort > gc_rec_pins && |
| 155 | + drun "ipfs pin ls --type=direct" | sort > gc_dir_pins && |
| 156 | + drun "ipfs pin ls --type=indirect" | sort > gc_ind_pins |
| 157 | +' |
| 158 | + |
| 159 | +test_expect_success "pins all look the same" ' |
| 160 | + test_cmp start_rec_pins gc_rec_pins && |
| 161 | + test_cmp start_dir_pins gc_dir_pins && |
| 162 | + test_cmp start_ind_pins gc_ind_pins |
| 163 | +' |
| 164 | + |
| 165 | +test_expect_success "fetch all refs" ' |
| 166 | + drun "ipfs refs local" | sort | uniq > post_gc_refs |
| 167 | +' |
| 168 | + |
| 169 | +first_elems() { |
| 170 | + cat "$1" | awk '{ print $1 }' |
| 171 | +} |
| 172 | + |
| 173 | +test_expect_success "get just hashes of pins" ' |
| 174 | + first_elems all_pinned | sort | uniq > all_pinned_refs |
| 175 | +' |
| 176 | + |
| 177 | +test_stop_daemon $DOCID |
| 178 | + |
| 179 | +test_can_fetch_buggy_hashes() { |
| 180 | + ref_file="$1" |
| 181 | + for ref in `cat $ref_file`; do |
| 182 | + if ! drun "ipfs block get $ref" > /dev/null; then |
| 183 | + echo "FAILURE: $ref" |
| 184 | + return 1 |
| 185 | + fi |
| 186 | + done |
| 187 | +} |
| 188 | + |
| 189 | +# this bug was fixed in 0.4.3 |
| 190 | +test_expect_success "no pinned objects are missing from local refs" ' |
| 191 | + comm -23 all_pinned_refs post_gc_refs > missing_pinned_objects && |
| 192 | + echo "" > empty_file && |
| 193 | + test_cmp empty_file missing_pinned_objects |
| 194 | +' |
| 195 | + |
| 196 | +test_expect_success "make a couple more files" ' |
| 197 | + drun "$GUEST_RANDOM_FILES -depth=$DEPTH -dirs=$NBDIR -files=$NBFILE many_more_files" > more_filenames |
| 198 | +' |
| 199 | + |
| 200 | +test_expect_success "add the new files" ' |
| 201 | + drun "ipfs add -r -q many_more_files" | tee more_hashes |
| 202 | +' |
| 203 | + |
| 204 | +test_expect_success "unpin root so we can do things ourselves" ' |
| 205 | + drun "ipfs pin rm $(tail -n1 more_hashes)" |
| 206 | +' |
| 207 | + |
| 208 | +test_expect_success "select random subset to pin recursively and directly" ' |
| 209 | + sort -R more_hashes | head -n$PINTOTAL > more_topin && |
| 210 | + head -n$PINEACH more_topin > more_recurpins && |
| 211 | + tail -n$PINEACH more_topin > more_directpins |
| 212 | +' |
| 213 | + |
| 214 | +test_expect_success "pin some objects recursively" ' |
| 215 | + pin_hashes more_recurpins |
| 216 | +' |
| 217 | + |
| 218 | +test_expect_success "pin some objects directly" ' |
| 219 | + pin_hashes more_directpins "-r=false" |
| 220 | +' |
| 221 | + |
| 222 | +test_expect_success "get full ref list" ' |
| 223 | + drun "ipfs refs local" | sort > more_start_refs |
| 224 | +' |
| 225 | + |
| 226 | +test_expect_success "get pin lists" ' |
| 227 | + drun "ipfs pin ls --type=recursive" | sort > more_start_rec_pins && |
| 228 | + drun "ipfs pin ls --type=direct" | sort > more_start_dir_pins && |
| 229 | + drun "ipfs pin ls --type=indirect" | sort > more_start_ind_pins |
| 230 | +' |
| 231 | + |
| 232 | +test_expect_success "'ipfs-3-to-4 -revert' succeeds" ' |
| 233 | + drun "$GUEST_IPFS_3_TO_4 -revert -path=/root/.ipfs" >actual |
| 234 | +' |
| 235 | + |
| 236 | +test_expect_success "'ipfs-3-to-4 -revert' output looks good" ' |
| 237 | + grep "writing keys:" actual || |
| 238 | + test_fsh cat actual |
| 239 | +' |
| 240 | + |
| 241 | +test_install_version "v0.4.2" |
| 242 | + |
| 243 | +test_start_daemon $DOCID |
| 244 | + |
| 245 | +test_expect_success "list all refs after reverting migration" ' |
| 246 | + drun "ipfs refs local" | sort > after_revert_refs |
| 247 | +' |
| 248 | + |
| 249 | +test_expect_success "list all pins after reverting migration" ' |
| 250 | + drun "ipfs pin ls --type=recursive" | sort > after_revert_rec_pins && |
| 251 | + drun "ipfs pin ls --type=direct" | sort > after_revert_dir_pins && |
| 252 | + drun "ipfs pin ls --type=indirect" | sort > after_revert_ind_pins |
| 253 | +' |
| 254 | + |
| 255 | +test_expect_success "refs look right" ' |
| 256 | + comm -23 more_start_refs after_revert_refs > missing_refs && |
| 257 | + test_cmp missing_refs empty_refs_file |
| 258 | +' |
| 259 | + |
| 260 | +test_expect_success "pins all look the same" ' |
| 261 | + test_cmp more_start_rec_pins after_revert_rec_pins && |
| 262 | + test_cmp more_start_dir_pins after_revert_dir_pins && |
| 263 | + test_cmp more_start_ind_pins after_revert_ind_pins |
| 264 | +' |
| 265 | + |
| 266 | +test_expect_success "manually compute gc set" ' |
| 267 | + cat after_revert_rec_pins after_revert_dir_pins after_revert_ind_pins | sort > after_revert_all_pinned |
| 268 | +' |
| 269 | + |
| 270 | +test_expect_success "run a gc" ' |
| 271 | + drun "ipfs repo gc" | sort > gc_out |
| 272 | +' |
| 273 | + |
| 274 | +test_expect_success "no pinned objects were gc'ed" ' |
| 275 | + comm -12 gc_out after_revert_all_pinned > gced_pinned_objects && |
| 276 | + test_cmp empty_refs_file gced_pinned_objects |
| 277 | +' |
| 278 | + |
| 279 | +test_stop_daemon $DOCID |
| 280 | + |
| 281 | +test_expect_success "stop docker container" ' |
| 282 | + stop_docker "$DOCID" |
| 283 | +' |
| 284 | + |
| 285 | +test_done |
0 commit comments