master
sh 74 lines 1.89 KB
Raw
1 #!/usr/bin/env bash
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 skip_all="skipping auto repo gc tests until they can be fixed"
11
12 test_done
13
14 check_ipfs_storage() {
15 ipfs config Datastore.StorageMax
16 }
17
18 test_init_ipfs
19
20 test_expect_success "generate 2 600 kB files and 2 MB file using random-data" '
21 random-data -size=614400 -seed=41 >600k1 &&
22 random-data -size=614400 -seed=42 >600k2 &&
23 random-data -size=2097152 -seed=43 >2M
24 '
25
26 test_expect_success "set ipfs gc watermark, storage max, and gc timeout" '
27 test_config_set Datastore.StorageMax "2MB" &&
28 test_config_set --json Datastore.StorageGCWatermark 60 &&
29 test_config_set Datastore.GCPeriod "20ms"
30 '
31
32 test_launch_ipfs_daemon --enable-gc
33
34 test_gc() {
35 test_expect_success "adding data below watermark doesn't trigger auto gc" '
36 ipfs add 600k1 >/dev/null &&
37 disk_usage "$IPFS_PATH/blocks" >expected &&
38 go-sleep 40ms &&
39 disk_usage "$IPFS_PATH/blocks" >actual &&
40 test_cmp expected actual
41 '
42
43 test_expect_success "adding data beyond watermark triggers auto gc" '
44 HASH=`ipfs add -q 600k2` &&
45 ipfs pin rm -r $HASH &&
46 go-sleep 40ms &&
47 DU=$(disk_usage "$IPFS_PATH/blocks") &&
48 if test $(uname -s) = "Darwin"; then
49 test "$DU" -lt 1400 # 60% of 2MB
50 else
51 test "$DU" -lt 1000000
52 fi
53 '
54 }
55
56 #TODO: conditional GC test is disabled due to files size bug in ipfs add
57 #test_expect_success "adding data beyond storageMax fails" '
58 # test_must_fail ipfs add 2M 2>add_fail_out
59 #'
60 #test_expect_success "ipfs add not enough space message looks good" '
61 # echo "Error: file size exceeds slack space allowed by storageMax. Maybe unpin some files?" >add_fail_exp &&
62 # test_cmp add_fail_exp add_fail_out
63 #'
64
65 test_expect_success "periodic auto gc stress test" '
66 for i in $(test_seq 1 20)
67 do
68 test_gc || return 1
69 done
70 '
71
72 test_kill_ipfs_daemon
73
74 test_done