@cryptotaxi247 / kubo / commits / c70911325

gc: add sharness test script

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Feb 23, 2017 at 02:50 UTC c7091132577666d687b223aa6054733add45c889
1 file changed +161
test/sharness/t0087-repo-robust-gc.sh new
+161
@@ -0,0 +1,161 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2016 Jeromy Johnson
4 +# MIT Licensed; see the LICENSE file in this repository.
5 +#
6 +
7 +test_description="Test robustness of garbage collector"
8 +
9 +. lib/test-lib.sh
10 +set -e
11 +
12 +test_gc_robust_part1() {
13 +
14 + test_expect_success "add a 1MB file with --raw-leaves" '
15 + random 1048576 56 > afile &&
16 + HASH1=`ipfs add --raw-leaves -q afile`
17 + '
18 +
19 + HASH1FILE=.ipfs/blocks/L3/CIQNIPL4GP62ZMNNSLZ2G33Z3T5VAN3YHCJTGT5FG45XWH5FGZRXL3A.data
20 +
21 + LEAF1=zb2rhZWKCMcHCfCym41ocwE5BhNQsEVLrwBkLEQaxJzRHHZch
22 + LEAF1FILE=.ipfs/blocks/C2/AFKREIBKRCW7HF6NHR6DVWECQXC5RQC7U7PKHKTI53BYYZNQP23DK5FC2Y.data
23 +
24 + LEAF2=zb2rhdUpCuyoQPRtvBW8JhAEfPaNd9dBb3QQCMMWYS1V8hjBR
25 + LEAF2FILE=.ipfs/blocks/Q6/BAFKREIDFSUIR43GJPHNDXXQA45GJVNRZBET3CRPUMYJCBLK3RTN7ZAMQ6Q
26 +
27 + LEAF3=zb2rhnwyvreekPqEMAbKqs35KYHxkNi7pXED7L2TfJKveTTva
28 + LEAF4=zb2rhnvAVvfDDnndcfQkwqNgUm94ba3zBSXyJKCfVXwU4FXx2
29 +
30 + test_expect_success "remove a leaf node from the repo manually" '
31 + rm "$LEAF1FILE"
32 + '
33 +
34 + test_expect_success "check that the node is removed" '
35 + test_must_fail ipfs cat $HASH1
36 + '
37 +
38 + test_expect_success "'ipfs repo gc' should still be be fine" '
39 + ipfs repo gc
40 + '
41 +
42 + test_expect_success "corrupt the root node of 1MB file" '
43 + test -e "$HASH1FILE" &&
44 + dd if=/dev/zero of="$HASH1FILE" count=1 bs=100 conv=notrunc
45 + '
46 +
47 + test_expect_success "'ipfs repo gc' should abort without removing anything" '
48 + test_must_fail ipfs repo gc 2>&1 | tee gc_err &&
49 + grep -q "could not retrieve links for $HASH1" gc_err &&
50 + grep -q "aborted" gc_err
51 + '
52 +
53 + test_expect_success "leaf nodes were not removed after gc" '
54 + ipfs cat $LEAF3 > /dev/null &&
55 + ipfs cat $LEAF4 > /dev/null
56 + '
57 +
58 + test_expect_success "unpin the 1MB file" '
59 + ipfs pin rm $HASH1
60 + '
61 +
62 + # make sure the permission problem is fixed on exit, otherwise cleanup
63 + # will fail
64 + trap "chmod 700 `dirname "$LEAF2FILE"` 2> /dev/null || true" 0
65 +
66 + test_expect_success "create a permission problem" '
67 + chmod 500 `dirname "$LEAF2FILE"` &&
68 + test_must_fail ipfs block rm $LEAF2 2>&1 | tee block_rm_err &&
69 + grep -q "permission denied" block_rm_err
70 + '
71 +
72 + test_expect_success "'ipfs repo gc' should still run and remove as much as possible" '
73 + test_must_fail ipfs repo gc 2>&1 | tee repo_gc_out &&
74 + grep -q "removed $HASH1" repo_gc_out &&
75 + grep -q "could not remove $LEAF2" repo_gc_out &&
76 + grep -q "removed $LEAF3" repo_gc_out &&
77 + grep -q "removed $LEAF4" repo_gc_out
78 + '
79 +
80 + test_expect_success "fix the permission problem" '
81 + chmod 700 `dirname "$LEAF2FILE"`
82 + '
83 +
84 + test_expect_success "'ipfs repo gc' should be ok now" '
85 + ipfs repo gc | tee repo_gc_out
86 + grep -q "removed $LEAF2" repo_gc_out
87 + '
88 +}
89 +
90 +test_gc_robust_part2() {
91 +
92 + test_expect_success "add 1MB file normally (i.e., without raw leaves)" '
93 + random 1048576 56 > afile &&
94 + HASH2=`ipfs add -q afile`
95 + '
96 +
97 + LEAF1=QmSijovevteoY63Uj1uC5b8pkpDU5Jgyk2dYBqz3sMJUPc
98 + LEAF1FILE=.ipfs/blocks/ME/CIQECF2K344QITW5S6E6H6T4DOXDDB2XA2V7BBOCIMN2VVF4Q77SMEY.data
99 +
100 + LEAF2=QmTbPEyrA1JyGUHFvmtx1FNZVzdBreMv8Hc8jV9sBRWhNA
101 + LEAF2FILE=.ipfs/blocks/WM/CIQE4EFIJN2SUTQYSKMKNG7VM75W3SXT6LWJCHJJ73UAWN73WCX3WMY.data
102 +
103 + test_expect_success "add some additional unpinned content" '
104 + random 1000 3 > junk1 &&
105 + random 1000 4 > junk2 &&
106 + JUNK1=`ipfs add --pin=false -q junk1` &&
107 + JUNK2=`ipfs add --pin=false -q junk2`
108 + '
109 +
110 + test_expect_success "remove a leaf node from the repo manually" '
111 + rm "$LEAF1FILE"
112 + '
113 +
114 + test_expect_success "'ipfs repo gc' should abort" '
115 + test_must_fail ipfs repo gc 2>&1 | tee repo_gc_out &&
116 + grep -q "could not retrieve links for $LEAF1" repo_gc_out &&
117 + grep -q "aborted" repo_gc_out
118 + '
119 +
120 + test_expect_success "test that garbage collector really aborted" '
121 + ipfs cat $JUNK1 > /dev/null &&
122 + ipfs cat $JUNK2 > /dev/null
123 + '
124 +
125 + test_expect_success "corrupt a key" '
126 + test -e "$LEAF2FILE" &&
127 + dd if=/dev/zero of="$LEAF2FILE" count=1 bs=100 conv=notrunc
128 + '
129 +
130 + test_expect_success "'ipfs repo gc' should abort with two errors" '
131 + test_must_fail ipfs repo gc 2>&1 | tee repo_gc_out &&
132 + grep -q "could not retrieve links for $LEAF1" repo_gc_out &&
133 + grep -q "could not retrieve links for $LEAF2" repo_gc_out &&
134 + grep -q "aborted" repo_gc_out
135 + '
136 +
137 + test_expect_success "unpin 1MB file" '
138 + ipfs pin rm $HASH2
139 + '
140 +
141 + test_expect_success "'ipfs repo gc' should be fine now" '
142 + ipfs repo gc | tee repo_gc_out &&
143 + grep -q "removed $HASH2" repo_gc_out &&
144 + grep -q "removed $LEAF2" repo_gc_out
145 + '
146 +}
147 +
148 +test_init_ipfs
149 +
150 +test_gc_robust_part1
151 +test_gc_robust_part2
152 +
153 +test_launch_ipfs_daemon --offline
154 +
155 +test_gc_robust_part1
156 +test_gc_robust_part2
157 +
158 +test_kill_ipfs_daemon
159 +
160 +test_done
161 +