Skip to content

Commit fbea64c

Browse files
committed
testsuite: cover corrupted sqlite database
Problem: there is no coverage for content-sqlite's handling of a corrupt database file. Despite having https://www.sqlite.org/fileformat.html, I was unsuccessful trying to create the specific form of corruption reported in #4338. However, it is trivial to simulate a couple of other types of fatal errors by corrupting the database file.
1 parent 5f3d1e7 commit fbea64c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

t/t0012-content-sqlite.t

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,41 @@ test_expect_success 'run flux with statedir and verify modes' '
271271
grep "journal_mode=WAL synchronous=NORMAL" logs4
272272
'
273273

274+
# Will create in WAL mode since statedir is set
275+
recreate_database()
276+
{
277+
flux start -o,-Sbroker.rc1_path=,-Sbroker.rc3_path= \
278+
-o,-Sstatedir=$(pwd) bash -c \
279+
"flux module load content-sqlite truncate; \
280+
flux module remove content-sqlite"
281+
}
282+
load_module_xfail()
283+
{
284+
flux start -o,-Sbroker.rc1_path=,-Sbroker.rc3_path= \
285+
-o,-Sstatedir=$(pwd) flux module load content-sqlite
286+
}
287+
288+
# FWIW https://www.sqlite.org/fileformat.html
289+
test_expect_success 'create database with bad header magic' '
290+
recreate_database &&
291+
echo "xxxxxxxxxxxxxxxx" | dd obs=1 count=16 seek=0 of=content.sqlite
292+
'
293+
test_expect_success 'module load fails with not a database error' '
294+
test_must_fail load_module_xfail 2>notdb.err &&
295+
grep "not a database" notdb.err
296+
'
297+
test_expect_success 'create database with bad schema format number' '
298+
recreate_database &&
299+
echo "\001\001\001\001" | dd obs=1 count=4 seek=44 of=content.sqlite
300+
'
301+
test_expect_success 'module load fails with database image is malformed error' '
302+
test_must_fail load_module_xfail 2>maldb.err &&
303+
grep "database disk image is malformed" maldb.err
304+
'
305+
test_expect_success 'full instance start fails with malformed sqlite db' '
306+
test_must_fail flux start -o,-Sstatedir=$(pwd) /bin/true
307+
'
308+
274309
test_expect_success 'remove content-sqlite module on rank 0' '
275310
flux module remove content-sqlite
276311
'

0 commit comments

Comments
 (0)