Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: third_party/sqlite/src/test/pagerfault.test

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2010 June 15 1 # 2010 June 15
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
11 # 11 #
12 12
13 set testdir [file dirname $argv0] 13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl 14 source $testdir/tester.tcl
15 source $testdir/lock_common.tcl 15 source $testdir/lock_common.tcl
16 source $testdir/malloc_common.tcl 16 source $testdir/malloc_common.tcl
17 17
18 if {[permutation] == "inmemory_journal"} { 18 if {[permutation] == "inmemory_journal"} {
19 finish_test 19 finish_test
20 return 20 return
21 } 21 }
22 22
23 if {$::tcl_platform(platform)=="windows"} {
24 finish_test
25 return
26 }
27
23 set a_string_counter 1 28 set a_string_counter 1
24 proc a_string {n} { 29 proc a_string {n} {
25 global a_string_counter 30 global a_string_counter
26 incr a_string_counter 31 incr a_string_counter
27 string range [string repeat "${a_string_counter}." $n] 1 $n 32 string range [string repeat "${a_string_counter}." $n] 1 $n
28 } 33 }
29 db func a_string a_string 34 db func a_string a_string
30 35
31 #------------------------------------------------------------------------- 36 #-------------------------------------------------------------------------
32 # Test fault-injection while rolling back a hot-journal file. 37 # Test fault-injection while rolling back a hot-journal file.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 226 }
222 } -body { 227 } -body {
223 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 } 228 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
224 } -test { 229 } -test {
225 faultsim_test_result {0 {}} 230 faultsim_test_result {0 {}}
226 faultsim_integrity_check 231 faultsim_integrity_check
227 } 232 }
228 do_faultsim_test pagerfault-5.3 -faults oom-transient -prep { 233 do_faultsim_test pagerfault-5.3 -faults oom-transient -prep {
229 faultsim_restore_and_reopen 234 faultsim_restore_and_reopen
230 db func a_string a_string 235 db func a_string a_string
231 file delete -force test2.db test2.db-journal test2.db-wal 236 forcedelete test2.db test2.db-journal test2.db-wal
232 execsql { 237 execsql {
233 PRAGMA journal_mode = PERSIST; 238 PRAGMA journal_mode = PERSIST;
234 ATTACH 'test2.db' AS aux; 239 ATTACH 'test2.db' AS aux;
235 PRAGMA aux.journal_mode = PERSIST; 240 PRAGMA aux.journal_mode = PERSIST;
236 PRAGMA aux.journal_size_limit = 0; 241 PRAGMA aux.journal_size_limit = 0;
237 } 242 }
238 } -body { 243 } -body {
239 execsql { 244 execsql {
240 BEGIN; 245 BEGIN;
241 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; 246 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 faultsim_delete_and_reopen 634 faultsim_delete_and_reopen
630 db func a_string a_string; 635 db func a_string a_string;
631 execsql { 636 execsql {
632 PRAGMA journal_mode = PERSIST; 637 PRAGMA journal_mode = PERSIST;
633 BEGIN; 638 BEGIN;
634 CREATE TABLE t1(x, y UNIQUE); 639 CREATE TABLE t1(x, y UNIQUE);
635 INSERT INTO t1 VALUES(a_string(333), a_string(444)); 640 INSERT INTO t1 VALUES(a_string(333), a_string(444));
636 COMMIT; 641 COMMIT;
637 } 642 }
638 db close 643 db close
639 file delete -force test.db 644 forcedelete test.db
640 faultsim_save 645 faultsim_save
641 } {} 646 } {}
642 do_faultsim_test pagerfault-13 -prep { 647 do_faultsim_test pagerfault-13 -prep {
643 faultsim_restore_and_reopen 648 faultsim_restore_and_reopen
644 } -body { 649 } -body {
645 execsql { CREATE TABLE xx(a, b) } 650 execsql { CREATE TABLE xx(a, b) }
646 } -test { 651 } -test {
647 faultsim_test_result {0 {}} 652 faultsim_test_result {0 {}}
648 } 653 }
649 654
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 # has successfully returned. i.e. the series of calls for the aborted commit 1099 # has successfully returned. i.e. the series of calls for the aborted commit
1095 # is: 1100 # is:
1096 # 1101 #
1097 # PagerCommitPhaseOne(<in-memory-db>) -> SQLITE_OK 1102 # PagerCommitPhaseOne(<in-memory-db>) -> SQLITE_OK
1098 # PagerCommitPhaseOne(<file-db>) -> SQLITE_IOERR 1103 # PagerCommitPhaseOne(<file-db>) -> SQLITE_IOERR
1099 # PagerRollback(<in-memory-db>) 1104 # PagerRollback(<in-memory-db>)
1100 # PagerRollback(<file-db>) 1105 # PagerRollback(<file-db>)
1101 # 1106 #
1102 do_faultsim_test pagerfault-23 -prep { 1107 do_faultsim_test pagerfault-23 -prep {
1103 sqlite3 db :memory: 1108 sqlite3 db :memory:
1104 foreach f [glob -nocomplain test.db*] { file delete -force $f } 1109 foreach f [glob -nocomplain test.db*] { forcedelete $f }
1105 db eval { 1110 db eval {
1106 ATTACH 'test.db2' AS aux; 1111 ATTACH 'test.db2' AS aux;
1107 CREATE TABLE t1(a, b); 1112 CREATE TABLE t1(a, b);
1108 CREATE TABLE aux.t2(a, b); 1113 CREATE TABLE aux.t2(a, b);
1109 } 1114 }
1110 } -body { 1115 } -body {
1111 execsql { 1116 execsql {
1112 BEGIN; 1117 BEGIN;
1113 INSERT INTO t1 VALUES(1,2); 1118 INSERT INTO t1 VALUES(1,2);
1114 INSERT INTO t2 VALUES(3,4); 1119 INSERT INTO t2 VALUES(3,4);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 } -body { 1239 } -body {
1235 puts $::channel [string repeat abc 6000] 1240 puts $::channel [string repeat abc 6000]
1236 flush $::channel 1241 flush $::channel
1237 } -test { 1242 } -test {
1238 catchsql { UPDATE t2 SET a = a_string(800), b = a_string(800) } 1243 catchsql { UPDATE t2 SET a = a_string(800), b = a_string(800) }
1239 catch { close $::channel } 1244 catch { close $::channel }
1240 catchsql { ROLLBACK } 1245 catchsql { ROLLBACK }
1241 faultsim_integrity_check 1246 faultsim_integrity_check
1242 } 1247 }
1243 1248
1249
1250 #-------------------------------------------------------------------------
1251 #
1252 do_test pagerfault-28-pre {
1253 faultsim_delete_and_reopen
1254 db func a_string a_string
1255 execsql {
1256 PRAGMA page_size = 512;
1257
1258 PRAGMA journal_mode = wal;
1259 PRAGMA wal_autocheckpoint = 0;
1260 PRAGMA cache_size = 100000;
1261
1262 BEGIN;
1263 CREATE TABLE t2(a UNIQUE, b UNIQUE);
1264 INSERT INTO t2 VALUES( a_string(800), a_string(800) );
1265 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1266 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1267 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1268 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1269 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1270 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1271 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1272 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1273 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1274 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1275 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1276 COMMIT;
1277 CREATE TABLE t1(a PRIMARY KEY, b);
1278 }
1279 expr {[file size test.db-shm] >= 96*1024}
1280 } {1}
1281 faultsim_save_and_close
1282
1283 do_faultsim_test pagerfault-28a -faults oom* -prep {
1284 faultsim_restore_and_reopen
1285 execsql { PRAGMA mmap_size=0 }
1286
1287 sqlite3 db2 test.db
1288 db2 eval { SELECT count(*) FROM t2 }
1289
1290 db func a_string a_string
1291 execsql {
1292 BEGIN;
1293 INSERT INTO t1 VALUES(a_string(2000), a_string(2000));
1294 INSERT INTO t1 VALUES(a_string(2000), a_string(2000));
1295 }
1296 set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY a" -1 DUMMY]
1297 sqlite3_step $::STMT
1298 } -body {
1299 execsql { ROLLBACK }
1300 } -test {
1301 db2 close
1302 sqlite3_finalize $::STMT
1303 catchsql { ROLLBACK }
1304 faultsim_integrity_check
1305 }
1306
1307 faultsim_restore_and_reopen
1308 sqlite3 db2 test.db
1309 db2 eval {SELECT count(*) FROM t2}
1310 db close
1311
1312 do_faultsim_test pagerfault-28b -faults oom* -prep {
1313 sqlite3 db test.db
1314 } -body {
1315 execsql { SELECT count(*) FROM t2 }
1316 } -test {
1317 faultsim_test_result {0 2048}
1318 db close
1319 }
1320
1321 db2 close
1322
1323 #-------------------------------------------------------------------------
1324 # Try this:
1325 #
1326 # 1) Put the pager in ERROR state (error during rollback)
1327 #
1328 # 2) Next time the connection is used inject errors into all xWrite() and
1329 # xUnlock() calls. This causes the hot-journal rollback to fail and
1330 # the pager to declare its locking state UNKNOWN.
1331 #
1332 # 3) Same again.
1333 #
1334 # 4a) Stop injecting errors. Allow the rollback to succeed. Check that
1335 # the database is Ok. Or,
1336 #
1337 # 4b) Close and reopen the db. Check that the db is Ok.
1338 #
1339 proc custom_injectinstall {} {
1340 testvfs custom -default true
1341 custom filter {xWrite xUnlock}
1342 }
1343 proc custom_injectuninstall {} {
1344 catch {db close}
1345 catch {db2 close}
1346 custom delete
1347 }
1348 proc custom_injectstart {iFail} {
1349 custom ioerr $iFail 1
1350 }
1351 proc custom_injectstop {} {
1352 custom ioerr
1353 }
1354 set ::FAULTSIM(custom) [list \
1355 -injectinstall custom_injectinstall \
1356 -injectstart custom_injectstart \
1357 -injectstop custom_injectstop \
1358 -injecterrlist {{1 {disk I/O error}}} \
1359 -injectuninstall custom_injectuninstall \
1360 ]
1361
1362 do_test pagerfault-29-pre {
1363 faultsim_delete_and_reopen
1364 db func a_string a_string
1365 execsql {
1366 PRAGMA page_size = 1024;
1367 PRAGMA cache_size = 5;
1368
1369 BEGIN;
1370 CREATE TABLE t2(a UNIQUE, b UNIQUE);
1371 INSERT INTO t2 VALUES( a_string(800), a_string(800) );
1372 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1373 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1374 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1375 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1376 COMMIT;
1377 }
1378 expr {[file size test.db] >= 50*1024}
1379 } {1}
1380 faultsim_save_and_close
1381 foreach {tn tt} {
1382 29 { catchsql ROLLBACK }
1383 30 { db close ; sqlite3 db test.db }
1384 } {
1385 do_faultsim_test pagerfault-$tn -faults custom -prep {
1386 faultsim_restore_and_reopen
1387 db func a_string a_string
1388 execsql {
1389 PRAGMA cache_size = 5;
1390 BEGIN;
1391 UPDATE t2 SET a = a_string(799);
1392 }
1393 } -body {
1394 catchsql ROLLBACK
1395 catchsql ROLLBACK
1396 catchsql ROLLBACK
1397 } -test {
1398 eval $::tt
1399 if {"ok" != [db one {PRAGMA integrity_check}]} {
1400 error "integrity check failed"
1401 }
1402 }
1403 }
1404
1405 do_test pagerfault-31-pre {
1406 sqlite3_shutdown
1407 sqlite3_config_uri 1
1408 } {SQLITE_OK}
1409 do_faultsim_test pagerfault-31 -faults oom* -body {
1410 sqlite3 db {file:one?mode=memory&cache=shared}
1411 db eval {
1412 CREATE TABLE t1(x);
1413 INSERT INTO t1 VALUES(1);
1414 SELECT * FROM t1;
1415 }
1416 } -test {
1417 faultsim_test_result {0 1} {1 {}}
1418 catch { db close }
1419 }
1420 sqlite3_shutdown
1421 sqlite3_config_uri 0
1422
1423 do_test pagerfault-32-pre {
1424 reset_db
1425 execsql {
1426 CREATE TABLE t1(x);
1427 INSERT INTO t1 VALUES('one');
1428 }
1429 } {}
1430 faultsim_save_and_close
1431
1432 do_faultsim_test pagerfault-32 -prep {
1433 faultsim_restore_and_reopen
1434 db eval { SELECT * FROM t1; }
1435 } -body {
1436 execsql { SELECT * FROM t1; }
1437 } -test {
1438 faultsim_test_result {0 one}
1439 }
1440 sqlite3_shutdown
1441 sqlite3_config_uri 0
1442
1443 do_faultsim_test pagerfault-33a -prep {
1444 sqlite3 db :memory:
1445 execsql {
1446 CREATE TABLE t1(a, b);
1447 INSERT INTO t1 VALUES(1, 2);
1448 }
1449 } -body {
1450 execsql { VACUUM }
1451 } -test {
1452 faultsim_test_result {0 {}}
1453 }
1454 do_faultsim_test pagerfault-33b -prep {
1455 sqlite3 db ""
1456 execsql {
1457 CREATE TABLE t1(a, b);
1458 INSERT INTO t1 VALUES(1, 2);
1459 }
1460 } -body {
1461 execsql { VACUUM }
1462 } -test {
1463 faultsim_test_result {0 {}}
1464 }
1465
1466 do_test pagerfault-34-pre {
1467 reset_db
1468 execsql {
1469 CREATE TABLE t1(x PRIMARY KEY);
1470 }
1471 } {}
1472 faultsim_save_and_close
1473 do_faultsim_test pagerfault-34 -prep {
1474 faultsim_restore_and_reopen
1475 execsql {
1476 BEGIN;
1477 INSERT INTO t1 VALUES( randomblob(4000) );
1478 DELETE FROM t1;
1479 }
1480 } -body {
1481 execsql COMMIT
1482 } -test {
1483 faultsim_test_result {0 {}}
1484 }
1485
1486 do_test pagerfault-35-pre {
1487 faultsim_delete_and_reopen
1488 execsql {
1489 CREATE TABLE t1(x PRIMARY KEY, y);
1490 INSERT INTO t1 VALUES(randomblob(200), randomblob(200));
1491 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
1492 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
1493 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
1494 }
1495 faultsim_save_and_close
1496 } {}
1497 testvfs tv -default 1
1498 tv sectorsize 8192;
1499 tv devchar [list]
1500 do_faultsim_test pagerfault-35 -prep {
1501 faultsim_restore_and_reopen
1502 } -body {
1503 execsql { UPDATE t1 SET x=randomblob(200) }
1504 } -test {
1505 faultsim_test_result {0 {}}
1506 }
1507 catch {db close}
1508 tv delete
1509
1510 sqlite3_shutdown
1511 sqlite3_config_uri 1
1512 do_test pagerfault-36-pre {
1513 faultsim_delete_and_reopen
1514 execsql {
1515 CREATE TABLE t1(x PRIMARY KEY, y);
1516 INSERT INTO t1 VALUES(randomblob(200), randomblob(200));
1517 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
1518 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
1519 INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
1520 }
1521 faultsim_save_and_close
1522 } {}
1523 do_faultsim_test pagerfault-36 -prep {
1524 faultsim_restore
1525 sqlite3 db file:test.db?cache=shared
1526 sqlite3 db2 file:test.db?cache=shared
1527 db2 eval {
1528 BEGIN;
1529 SELECT count(*) FROM sqlite_master;
1530 }
1531 db eval {
1532 PRAGMA cache_size = 1;
1533 BEGIN;
1534 UPDATE t1 SET x = randomblob(200);
1535 }
1536 } -body {
1537 execsql ROLLBACK db
1538 } -test {
1539 catch { db eval {UPDATE t1 SET x = randomblob(200)} }
1540 faultsim_test_result {0 {}}
1541 catch { db close }
1542 catch { db2 close }
1543 }
1544
1545 sqlite3_shutdown
1546 sqlite3_config_uri 0
1547 sqlite3_initialize
1548
1244 finish_test 1549 finish_test
1245
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698