@cryptotaxi247 / kubo / commits / 5772ac7a5

test(sharness): improve CAR tests to remove some potential races

* Instead of ensuring that we GC nothing, verify that the repo validates. * Avoid a race between removing the fifos and trying to read from them. * Avoid all 'bash -c' invocations. Instead, make liberal use of subshells and wait. Hopefully fixes #7123.

Steven Allen committed Apr 13, 2020 at 21:42 UTC 5772ac7a5f5b44a0806c2dcd76893aba22d614a6
1 file changed +29 -38
test/sharness/t0054-dag-car-import-export.sh
+29 -38
@@ -14,8 +14,8 @@ tab=$'\t'
14 reset_blockstore() {
15 node=$1
16
17 - ipfsi $node pin ls --quiet --type=recursive | ipfsi $node pin rm &>/dev/null
18 - ipfsi $node repo gc &>/dev/null
17 + ipfsi "$node" pin ls --quiet --type=recursive | ipfsi "$node" pin rm &>/dev/null
18 + ipfsi "$node" repo gc &>/dev/null
19
20 test_expect_success "pinlist empty" '
21 [[ -z "$( ipfsi $node pin ls )" ]]
@@ -27,18 +27,20 @@ reset_blockstore() {
27
28 # hammer with concurrent gc to ensure nothing clashes
29 do_import() {
30 - node=$1; shift
30 + node="$1"; shift
31 + (
32 + touch spin.gc
33
32 - # for tests below expecting this to be non -z
33 - echo "FIXME: BELOW TEST DISABLED FOR THE TIME BEING" > gc_out
34 + while [[ -e spin.gc ]]; do ipfsi "$node" repo gc &>/dev/null; done &
35 + while [[ -e spin.gc ]]; do ipfsi "$node" repo gc &>/dev/null; done &
36
35 - #touch spin.gc
36 - #timeout -s QUIT 30 bash -c "while [[ -e spin.gc ]]; do ipfsi $node repo gc &>>gc_out; done" & gc1_pid=$!
37 - #timeout -s QUIT 25 bash -c "while [[ -e spin.gc ]]; do ipfsi $node repo gc &>>gc_out; done" & gc2_pid=$!
37 + ipfsi "$node" dag import "$@" 2>&1 && ipfsi "$node" repo verify &>/dev/null
38 + result=$?
39
39 - timeout -s QUIT 20 bash -c "ipfsi $node dag import $* 2>&1"
40 -
41 - rm -f spin.gc || true
40 + rm -f spin.gc &>/dev/null
41 + wait
42 + exit $result
43 + )
44 }
45
46 run_online_imp_exp_tests() {
@@ -66,10 +68,6 @@ EOE
68 | sort > basic_import_actual
69 '
70
69 - # FIXME - positive-test the lack of output when https://github.com/ipfs/go-ipfs/issues/7121 is addressed
70 - test_expect_failure "concurrent GC did not manage to grab anything and remained silent" '
71 - test_cmp /dev/null gc_out
72 - '
71 test_expect_success "basic import output as expected" '
72 test_cmp basic_import_expected basic_import_actual
73 '
@@ -107,37 +105,30 @@ EOE
105 mkfifo pipe_testnet
106 mkfifo pipe_devnet
107
110 - # test that ipfs correctly opens both pipes and deleting them doesn't interfere with cleanup
111 - bash -c '
112 - sleep 1
113 - cat ../t0054-dag-car-import-export-data/lotus_testnet_export_128_shuffled_nulroot.car > pipe_testnet & cat1_pid=$!
114 - cat ../t0054-dag-car-import-export-data/lotus_devnet_genesis_shuffled_nulroot.car > pipe_devnet & cat2_pid=$!
115 -
116 - rm pipe_testnet pipe_devnet
108 + test_expect_success "fifo import" '
109 + (
110 + cat ../t0054-dag-car-import-export-data/lotus_testnet_export_128_shuffled_nulroot.car > pipe_testnet &
111 + cat ../t0054-dag-car-import-export-data/lotus_devnet_genesis_shuffled_nulroot.car > pipe_devnet &
112
118 - # extra safety valve to kill the cat processes in case something goes wrong
119 - bash -c "sleep 60; kill $cat1_pid $cat2_pid 2>/dev/null" &
120 - ' &
113 + do_import 0 \
114 + pipe_testnet \
115 + pipe_devnet \
116 + ../t0054-dag-car-import-export-data/combined_naked_roots_genesis_and_128.car \
117 + | sort > basic_fifo_import_actual
118 + result=$?
119
122 - test_expect_success "fifo import" '
123 - do_import 0 \
124 - pipe_testnet \
125 - pipe_devnet \
126 - ../t0054-dag-car-import-export-data/combined_naked_roots_genesis_and_128.car \
127 - | sort > basic_fifo_import_actual
120 + wait
121 + exit "$result"
122 + )
123 '
129 - # FIXME - positive-test the lack of output when https://github.com/ipfs/go-ipfs/issues/7121 is addressed
130 - test_expect_failure "concurrent GC did not manage to grab anything and remained silent" '
131 - test_cmp /dev/null gc_out
124 +
125 + test_expect_success "remove fifos" '
126 + rm pipe_testnet pipe_devnet
127 '
128
129 test_expect_success "fifo-import output as expected" '
130 test_cmp basic_import_expected basic_fifo_import_actual
131 '
137 -
138 - test_expect_success "fifos no longer present" '
139 - ! [[ -e pipe_testnet ]] && ! [[ -e pipe_devnet ]]
140 - '
132 }
133
134