Skip to content

Commit dd1ace2

Browse files
committed
t: cover flux-fsck
Problem: There are no flux-fsck tests. Add coverage in new t2816-fsck-cmd.t.
1 parent 4aa0a74 commit dd1ace2

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ TESTSCRIPTS = \
246246
t2813-flux-watch.t \
247247
t2814-hostlist-cmd.t \
248248
t2815-post-job-event.t \
249+
t2816-fsck-cmd.t \
249250
t2900-job-timelimits.t \
250251
t3000-mpi-basic.t \
251252
t3001-mpi-personalities.t \

t/t2816-fsck-cmd.t

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/sh
2+
3+
test_description='Test flux fsck command'
4+
5+
. $(dirname $0)/sharness.sh
6+
7+
test_under_flux 1 minimal
8+
9+
test_expect_success 'load content and content-sqlite module' '
10+
flux module load content &&
11+
flux module load content-sqlite
12+
'
13+
test_expect_success 'load kvs' '
14+
flux module load kvs
15+
'
16+
test_expect_success 'create some kvs content' '
17+
flux kvs put dir.a=test &&
18+
flux kvs put dir.b=test1 &&
19+
flux kvs put --append dir.b=test2 &&
20+
flux kvs put --append dir.b=test3 &&
21+
flux kvs put --append dir.b=test4 &&
22+
flux kvs put dir.c=testA &&
23+
flux kvs put --append dir.c=testB &&
24+
flux kvs put --append dir.c=testC &&
25+
flux kvs put --append dir.c=testD &&
26+
flux kvs link dir alink &&
27+
flux kvs namespace create testns &&
28+
flux kvs put --namespace=testns dir.a=testns
29+
'
30+
# N.B. startlog commands in rc scripts normally ensures a checkpoint
31+
# exists but we do this just to be extra sure
32+
test_expect_success 'call --sync to ensure we have checkpointed' '
33+
flux kvs put --sync dir.sync=foo
34+
'
35+
test_expect_success 'save some treeobjs for later' '
36+
flux kvs get --treeobj dir.b > dirb.out &&
37+
flux kvs get --treeobj dir.c > dirc.out
38+
'
39+
test_expect_success 'unload kvs' '
40+
flux module remove kvs
41+
'
42+
test_expect_success 'flux-fsck works' '
43+
flux fsck 2> simple.out &&
44+
grep "Checking integrity" simple.out &&
45+
grep "Total errors: 0" simple.out
46+
'
47+
test_expect_success 'flux-fsck verbose works' '
48+
flux fsck --verbose 2> verbose.out &&
49+
grep "dir\.a" verbose.out &&
50+
grep "dir\.b" verbose.out &&
51+
grep "alink" verbose.out
52+
'
53+
test_expect_success 'load kvs' '
54+
flux module load kvs
55+
'
56+
# unfortunately we don't have a `flux content remove` command, so we'll corrupt
57+
# a valref by overwriting a treeobj with a bad reference
58+
test_expect_success 'make a reference invalid' '
59+
cat dirb.out | jq -c .data[2]=\"sha1-1234567890123456789012345678901234567890\" > dirbbad.out &&
60+
flux kvs put --treeobj dir.b="$(cat dirbbad.out)"
61+
'
62+
test_expect_success 'unload kvs' '
63+
flux module remove kvs
64+
'
65+
# line count includes extra diagnostic messages
66+
test_expect_success 'flux-fsck detects errors' '
67+
test_must_fail flux fsck 2> fsckerrors1.out &&
68+
count=$(cat fsckerrors1.out | wc -l) &&
69+
test $count -eq 3 &&
70+
grep "dir\.b" fsckerrors1.out | grep "missing blobref" &&
71+
grep "Total errors: 1" fsckerrors1.out
72+
'
73+
test_expect_success 'flux-fsck no output with --quiet' '
74+
test_must_fail flux fsck --quiet 2> fsckerrors2.out &&
75+
count=$(cat fsckerrors2.out | wc -l) &&
76+
test $count -eq 0
77+
'
78+
test_expect_success 'load kvs' '
79+
flux module load kvs
80+
'
81+
test_expect_success 'make a reference invalid' '
82+
cat dirc.out | jq -c .data[2]=\"sha1-1234567890123456789012345678901234567890\" > dircbad.out &&
83+
flux kvs put --treeobj dir.c="$(cat dircbad.out)"
84+
'
85+
test_expect_success 'unload kvs' '
86+
flux module remove kvs
87+
'
88+
# line count includes extra diagnostic messages
89+
test_expect_success 'flux-fsck detects errors' '
90+
test_must_fail flux fsck 2> fsckerrors3.out &&
91+
count=$(cat fsckerrors3.out | wc -l) &&
92+
test $count -eq 4 &&
93+
grep "dir\.b" fsckerrors3.out | grep "missing blobref" &&
94+
grep "dir\.c" fsckerrors3.out | grep "missing blobref" &&
95+
grep "Total errors: 2" fsckerrors3.out
96+
'
97+
test_expect_success 'flux-fsck no output with --quiet' '
98+
test_must_fail flux fsck --quiet 2> fsckerrors4.out &&
99+
count=$(cat fsckerrors4.out | wc -l) &&
100+
test $count -eq 0
101+
'
102+
test_expect_success 'remove content & content-sqlite modules' '
103+
flux module remove content-sqlite &&
104+
flux module remove content
105+
'
106+
107+
test_done

0 commit comments

Comments
 (0)