Skip to content

Commit 712f745

Browse files
committed
testsuite: improve coverage of flux-archive
Problem: flux-archive is only partially covered by t0029-archive-mmap.t, which mainly covers the older mmap case. Add another test to cover newer options and use cases.
1 parent bdefc3e commit 712f745

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ TESTSCRIPTS = \
8989
t0017-security.t \
9090
t0018-content-files.t \
9191
t0020-terminus.t \
92+
t0021-archive-cmd.t \
9293
t0022-jj-reader.t \
9394
t0023-jobspec1-validate.t \
9495
t0026-flux-R.t \

t/t0021-archive-cmd.t

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#!/bin/sh
2+
3+
test_description='Test flux-archive'
4+
5+
. `dirname $0`/content/content-helper.sh
6+
7+
. `dirname $0`/sharness.sh
8+
9+
test_under_flux 2
10+
11+
# after test_under_flux is launched, cannot assume what umask is. An
12+
# unexpected umask could affect tests below. Hard code to 022 for
13+
# these tests.
14+
umask 022
15+
16+
# Usage: randbytes bytes
17+
randbytes() {
18+
dd if=/dev/random bs=$1 count=1
19+
}
20+
21+
test_expect_success 'flux archive create --badopt prints unrecognized option' '
22+
test_must_fail flux archive create --badopt 2>badopt.err &&
23+
grep "unrecognized option" badopt.err
24+
'
25+
test_expect_success 'flux archive create with no PATHs fails' '
26+
test_must_fail flux archive create
27+
'
28+
test_expect_success 'flux archive create with bad FLUX_URI fails' '
29+
(FLUX_URI=local:///noexist test_must_fail flux archive create .)
30+
'
31+
test_expect_success 'flux archive create fails with --overwrite --append' '
32+
test_must_fail flux archive create --overwrite --append .
33+
'
34+
test_expect_success 'flux archive create fails with -C baddir bad ' '
35+
test_must_fail flux archive create -C baddir .
36+
'
37+
test_expect_success 'flux archive create fails with FIFO in input' '
38+
mkfifo imafifo &&
39+
test_must_fail flux archive create imafifo
40+
'
41+
test_expect_success 'flux archive remove fails if archive doesnt exist' '
42+
test_must_fail flux archive remove
43+
'
44+
test_expect_success 'but it works with -f' '
45+
flux archive remove -f
46+
'
47+
# Set the small file threshold to 1K in these tests.
48+
# It's currently the default but just in case that changes.
49+
test_expect_success 'flux archive create works (small file)' '
50+
randbytes 128 >testfile &&
51+
flux archive create --small-file-threshold=1K -v testfile &&
52+
flux kvs get archive.main >archive.out
53+
'
54+
test_expect_success 'archive.main contains a base64-encoded file' '
55+
jq -e -r <archive.out ".[0].encoding == \"base64\""
56+
'
57+
test_expect_success 'flux archive create fails if archive exists' '
58+
test_must_fail flux archive create testfile
59+
'
60+
test_expect_success 'flux archive create --overwrite works (large file)' '
61+
randbytes 2048 >testfile2 &&
62+
flux archive create --overwrite --preserve \
63+
--small-file-threshold=1K -v testfile2 &&
64+
flux kvs get archive.main >archive2.out
65+
'
66+
test_expect_success 'and archive.main contains a blobvec-encoded file' '
67+
jq -e -r <archive2.out ".[0].encoding == \"blobvec\""
68+
'
69+
test_expect_success 'and archive.main_blobs exists due to --preserve' '
70+
flux kvs ls archive.main_blobs
71+
'
72+
test_expect_success 'flux archive create --append works (directory)' '
73+
mkdir -p testdir &&
74+
flux archive create --append testdir &&
75+
flux kvs get archive.main >archive3.out
76+
'
77+
test_expect_success 'and archive.main added an entry' '
78+
jq -e -r <archive3.out ".[1].path == \"testdir\""
79+
'
80+
test_expect_success 'flux archive list works' '
81+
flux archive list >list.out &&
82+
cat >list.exp <<-EOT &&
83+
testfile2
84+
testdir
85+
EOT
86+
test_cmp list.exp list.out
87+
'
88+
test_expect_success 'flux archive list -l works' '
89+
flux archive list --l >list_l.out &&
90+
cat >list_l.exp <<-EOT &&
91+
f 0644 2048 testfile2
92+
d 0755 0 testdir
93+
EOT
94+
test_cmp list_l.exp list_l.out
95+
'
96+
test_expect_success 'flux archive list with matching pattern works' '
97+
flux archive list testdir
98+
'
99+
test_expect_success 'flux archive list with non-matching pattern works' '
100+
flux archive list notinthere
101+
'
102+
test_expect_success 'flux archive extract -C baddir fails' '
103+
test_must_fail flux archive extract -C baddir
104+
'
105+
test_expect_success 'flux archive extract -n main -C gooddir works' '
106+
mkdir -p gooddir &&
107+
flux archive extract -n main -v -C gooddir
108+
'
109+
test_expect_success 'goodir/testfile2 was extracted faithfully' '
110+
test_cmp testfile2 gooddir/testfile2
111+
'
112+
test_expect_success 'goodir/testdir was extracted as a directory' '
113+
test -d gooddir/testdir
114+
'
115+
test_expect_success 'flux archive extract works with a non-matching pattern' '
116+
flux archive extract nomatch
117+
'
118+
test_expect_success 'flux archive extract works with a matching pattern' '
119+
mkdir -p gooddir2 &&
120+
flux archive extract -C gooddir2 testfile2 &&
121+
test_cmp testfile2 gooddir2/testfile2
122+
'
123+
test_expect_success 'flux archive remove works' '
124+
flux archive remove
125+
'
126+
test_expect_success 'and KVS keys are gone' '
127+
test_must_fail flux kvs ls archive.main_blobs &&
128+
test_must_fail flux kvs ls archive.main
129+
'
130+
test_expect_success 'flux archive list fails on nonexistent archive' '
131+
test_must_fail flux archive list &&
132+
test_must_fail flux archive list -n noexist
133+
'
134+
test_expect_success 'flux archive extract fails on nonexistent archive' '
135+
test_must_fail flux archive extract &&
136+
test_must_fail flux archive extract -n noexist
137+
'
138+
# This works because we use the primary namespace by default
139+
test_expect_success 'create an archive, then access it from a job' '
140+
flux archive create testfile &&
141+
flux run --label-io -N2 flux archive list
142+
'
143+
# but --no-force-primary allows FLUX_KVS_NAMESPACE to be used
144+
test_expect_success 'archive cannot be accessed from job with --no-force-primary' '
145+
test_must_fail flux run flux archive list --no-force-primary
146+
'
147+
# both producer and consumer use --no-force-primary within a job
148+
test_expect_success 'copy private archive from rank 0 to 1 of a job' '
149+
cat >job.sh <<-EOT &&
150+
#!/bin/sh
151+
opts="--no-force-primary -n mystuff"
152+
if test \$FLUX_TASK_RANK -eq 0; then
153+
flux archive create \$opts testfile2
154+
else
155+
mkdir jobdir
156+
flux archive extract -v --waitcreate \$opts -C jobdir
157+
fi
158+
EOT
159+
chmod +x job.sh &&
160+
flux run --label-io -N2 ./job.sh >job.out 2>&1
161+
'
162+
# Note: the current primary ns archive contains testfile not testfile2
163+
test_expect_success 'output references the private archive not primary ns' '
164+
cat >job.exp <<-EOT &&
165+
1: testfile2
166+
EOT
167+
test_cmp job.exp job.out
168+
'
169+
test_expect_success 'jobdir/testfile2 was extracted faithfully' '
170+
test_cmp testfile2 jobdir/testfile2
171+
'
172+
test_expect_success 'archive exists in job KVS guest directory' '
173+
jobdir=$(flux job last | flux job id --to=kvs) &&
174+
flux kvs get $jobdir.guest.archive.mystuff >/dev/null
175+
'
176+
177+
test_done

0 commit comments

Comments
 (0)