Add gc auto test
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Nov 15, 2015 at 17:15 UTC
54a98918221debd4bf525073ffb9c13eb705caaa
1 file changed
+70
test/sharness/t0082-repo-gc-auto.sh
new
+70
@@ -0,0 +1,70 @@
1
+#!/bin/sh
2
+#
3
+# MIT Licensed; see the LICENSE file in this repository.
4
+#
5
+
6
+test_description="Test ipfs repo auto gc"
7
+
8
+. lib/test-lib.sh
9
+
10
+check_ipfs_storage() {
11
+ ipfs config Datastore.StorageMax
12
+}
13
+
14
+test_init_ipfs
15
+
16
+test_expect_success "generate 2 600 kB files and 2 MB file using go-random" '
17
+ random 600k 41 >600k1 &&
18
+ random 600k 42 >600k2 &&
19
+ random 2M 43 >2M
20
+'
21
+
22
+test_expect_success "set ipfs gc watermark, storage max, and gc timeout" '
23
+ test_config_set Datastore.StorageMax "2MB" &&
24
+ test_config_set --json Datastore.StorageGCWatermark 60 &&
25
+ test_config_set Datastore.GCPeriod "20ms"
26
+'
27
+
28
+test_launch_ipfs_daemon --enable-gc
29
+
30
+test_gc() {
31
+ test_expect_success "adding data below watermark doesn't trigger auto gc" '
32
+ ipfs add 600k1 >/dev/null &&
33
+ disk_usage "$IPFS_PATH/blocks" >expected &&
34
+ go-sleep 40ms &&
35
+ disk_usage "$IPFS_PATH/blocks" >actual &&
36
+ test_cmp expected actual
37
+ '
38
+
39
+ test_expect_success "adding data beyond watermark triggers auto gc" '
40
+ HASH=`ipfs add -q 600k2` &&
41
+ ipfs pin rm -r $HASH &&
42
+ go-sleep 40ms &&
43
+ DU=$(disk_usage "$IPFS_PATH/blocks") &&
44
+ if test $(uname -s) = "Darwin"; then
45
+ test "$DU" -lt 1400 # 60% of 2MB
46
+ else
47
+ test "$DU" -lt 1000000
48
+ fi
49
+ '
50
+}
51
+
52
+#TODO: conditional GC test is disabled due to files size bug in ipfs add
53
+#test_expect_success "adding data beyond storageMax fails" '
54
+# test_must_fail ipfs add 2M 2>add_fail_out
55
+#'
56
+#test_expect_success "ipfs add not enough space message looks good" '
57
+# echo "Error: file size exceeds slack space allowed by storageMax. Maybe unpin some files?" >add_fail_exp &&
58
+# test_cmp add_fail_exp add_fail_out
59
+#'
60
+
61
+test_expect_success "periodic auto gc stress test" '
62
+ for i in $(test_seq 1 20)
63
+ do
64
+ test_gc
65
+ done
66
+'
67
+
68
+test_kill_ipfs_daemon
69
+
70
+test_done