Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add test cases to pager1.test and pager2.test. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
cc9ddae6d72b214f52b8949e644b91f4 |
User & Date: | dan 2010-06-21 18:29:41.000 |
Context
2010-06-21
| ||
20:19 | Fix comment inside the pager_unlock() routine. Always close the master journal file before trying to delete it. (check-in: f820b815c9 user: drh tags: trunk) | |
18:29 | Add test cases to pager1.test and pager2.test. (check-in: cc9ddae6d7 user: dan tags: trunk) | |
12:47 | Merge the experimental UNDELETABLE_WHEN_OPEN optimization into the trunk. (check-in: ee0acef1fa user: drh tags: trunk) | |
Changes
Changes to src/test_vfs.c.
︙ | ︙ | |||
86 87 88 89 90 91 92 | #define TESTVFS_DELETE_MASK 0x00000400 #define TESTVFS_CLOSE_MASK 0x00000800 #define TESTVFS_WRITE_MASK 0x00001000 #define TESTVFS_TRUNCATE_MASK 0x00002000 #define TESTVFS_ALL_MASK 0x00003FFF | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | #define TESTVFS_DELETE_MASK 0x00000400 #define TESTVFS_CLOSE_MASK 0x00000800 #define TESTVFS_WRITE_MASK 0x00001000 #define TESTVFS_TRUNCATE_MASK 0x00002000 #define TESTVFS_ALL_MASK 0x00003FFF #define TESTVFS_MAX_PAGES 1024 /* ** A shared-memory buffer. There is one of these objects for each shared ** memory region opened by clients. If two clients open the same file, ** there are two TestvfsFile structures but only one TestvfsBuffer structure. */ struct TestvfsBuffer { |
︙ | ︙ | |||
903 904 905 906 907 908 909 | if( !pBuffer ){ Tcl_AppendResult(interp, "no such file: ", Tcl_GetString(objv[2]), 0); return TCL_ERROR; } if( objc==4 ){ int n; u8 *a = Tcl_GetByteArrayFromObj(objv[3], &n); | | > | | | | | > > | | 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 | if( !pBuffer ){ Tcl_AppendResult(interp, "no such file: ", Tcl_GetString(objv[2]), 0); return TCL_ERROR; } if( objc==4 ){ int n; u8 *a = Tcl_GetByteArrayFromObj(objv[3], &n); int pgsz = pBuffer->pgsz; if( pgsz==0 ) pgsz = 32768; for(i=0; i*pgsz<n; i++){ int nByte = pgsz; tvfsAllocPage(pBuffer, i, pgsz); if( n-i*pgsz<pgsz ){ nByte = n; } memcpy(pBuffer->aPage[i], &a[i*pgsz], nByte); } } pObj = Tcl_NewObj(); for(i=0; pBuffer->aPage[i]; i++){ int pgsz = pBuffer->pgsz; if( pgsz==0 ) pgsz = 32768; Tcl_AppendObjToObj(pObj, Tcl_NewByteArrayObj(pBuffer->aPage[i], pgsz)); } Tcl_SetObjResult(interp, pObj); break; } case CMD_FILTER: { static struct VfsMethod { |
︙ | ︙ |
Changes to test/pager1.test.
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # # pager1-5.*: Cases related to multi-file commits. # # pager1-6.*: Cases related to "PRAGMA max_page_count" # # pager1-7.*: Cases specific to "PRAGMA journal_mode=TRUNCATE" # set a_string_counter 1 proc a_string {n} { global a_string_counter incr a_string_counter string range [string repeat "${a_string_counter}." $n] 1 $n } | > > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # # pager1-5.*: Cases related to multi-file commits. # # pager1-6.*: Cases related to "PRAGMA max_page_count" # # pager1-7.*: Cases specific to "PRAGMA journal_mode=TRUNCATE" # # pager1-8.*: Cases using temporary and in-memory databases. # set a_string_counter 1 proc a_string {n} { global a_string_counter incr a_string_counter string range [string repeat "${a_string_counter}." $n] 1 $n } |
︙ | ︙ | |||
175 176 177 178 179 180 181 | do_test pager1-$tn.27 { sql2 { SELECT * FROM t1 } } {21 one 22 two 23 three} do_test pager1-$tn.28 { sql3 { SELECT * FROM t1 } } {21 one 22 two 23 three} } #------------------------------------------------------------------------- # Savepoint related test cases. # | | | | | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | do_test pager1-$tn.27 { sql2 { SELECT * FROM t1 } } {21 one 22 two 23 three} do_test pager1-$tn.28 { sql3 { SELECT * FROM t1 } } {21 one 22 two 23 three} } #------------------------------------------------------------------------- # Savepoint related test cases. # do_test pager1-3.1.1 { faultsim_delete_and_reopen execsql { CREATE TABLE t1(a PRIMARY KEY, b); CREATE TABLE counter( i CHECK (i<5), u CHECK (u<10) ); INSERT INTO counter VALUES(0, 0); CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN UPDATE counter SET i = i+1; END; CREATE TRIGGER tr2 AFTER UPDATE ON t1 BEGIN UPDATE counter SET u = u+1; END; } execsql { SELECT * FROM counter } } {0 0} do_execsql_test pager1-3.1.2 { BEGIN; INSERT INTO t1 VALUES(1, randomblob(1500)); INSERT INTO t1 VALUES(2, randomblob(1500)); INSERT INTO t1 VALUES(3, randomblob(1500)); SELECT * FROM counter; } {3 0} do_catchsql_test pager1-3.1.3 { INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1 } {1 {constraint failed}} do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0} do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3} do_execsql_test pager1-3.6 { COMMIT } {} #------------------------------------------------------------------------- |
︙ | ︙ | |||
496 497 498 499 500 501 502 503 504 505 506 507 508 509 | } {won too free double-you why zed} } cd $pwd } db close tv delete #------------------------------------------------------------------------- # The following tests deal with multi-file commits. # # pager1-5.1.*: The case where a multi-file cannot be committed because # another connection is holding a SHARED lock on one of the # files. After the SHARED lock is removed, the COMMIT succeeds. | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | } {won too free double-you why zed} } cd $pwd } db close tv delete file delete -force $dirname # Set up a VFS to make a copy of the file-system just before deleting a # journal file to commit a transaction. The transaction modifies exactly # two database pages (and page 1 - the change counter). # testvfs tv -default 1 tv sectorsize 512 tv script copy_on_journal_delete tv filter xDelete set ::mj_filename_length 0 proc copy_on_journal_delete {method filename args} { if {[string match *journal $filename]} faultsim_save return SQLITE_OK } faultsim_delete_and_reopen do_execsql_test pager1.4.5.1 { PRAGMA page_size = 1024; CREATE TABLE t1(a, b); CREATE TABLE t2(a, b); INSERT INTO t1 VALUES('I', 'II'); INSERT INTO t2 VALUES('III', 'IV'); BEGIN; INSERT INTO t1 VALUES(1, 2); INSERT INTO t2 VALUES(3, 4); COMMIT; } {} tv filter {} # Check the transaction was committed: # do_execsql_test pager1.4.5.2 { SELECT * FROM t1; SELECT * FROM t2; } {I II 1 2 III IV 3 4} # Now try three tests: # # pager1-4.5.3: Restore the file-system. Check that the whole transaction # is rolled back. # # pager1-4.5.4: Restore the file-system. Corrupt the first record in the # journal. Check the transaction is not rolled back. # # pager1-4.5.5: Restore the file-system. Corrupt the second record in the # journal. Check that the first record in the transaction is # played back, but not the second. # faultsim_restore_and_reopen do_execsql_test pager1.4.5.3 { SELECT * FROM t1; SELECT * FROM t2; } {I II III IV} faultsim_restore_and_reopen hexio_write test.db-journal [expr 512+4+1024 - 202] 0123456789ABCDEF do_execsql_test pager1.4.5.4 { SELECT * FROM t1; SELECT * FROM t2; } {I II 1 2 III IV 3 4} faultsim_restore_and_reopen hexio_write test.db-journal [expr 512+4+1024+4+4+1024 - 202] 0123456789ABCDEF do_execsql_test pager1.4.5.5 { SELECT * FROM t1; SELECT * FROM t2; } {I II III IV 3 4} db close tv delete #------------------------------------------------------------------------- # The following tests deal with multi-file commits. # # pager1-5.1.*: The case where a multi-file cannot be committed because # another connection is holding a SHARED lock on one of the # files. After the SHARED lock is removed, the COMMIT succeeds. |
︙ | ︙ | |||
720 721 722 723 724 725 726 | }] { do_execsql_test pager1-7.1.$tn.1 $sql $res catch { set J -1 ; set J [file size test.db-journal] } catch { set W -1 ; set W [file size test.db-wal] } do_test pager1-7.1.$tn.2 { list $J $W } [list $js $ws] } | > > > > | | | | | | | | | | | | > | < | | | > > > > > > > > | 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | }] { do_execsql_test pager1-7.1.$tn.1 $sql $res catch { set J -1 ; set J [file size test.db-journal] } catch { set W -1 ; set W [file size test.db-wal] } do_test pager1-7.1.$tn.2 { list $J $W } [list $js $ws] } foreach {tn filename} { 1 :memory: 2 "" } { do_test pager1-8.$tn.1 { faultsim_delete_and_reopen db close sqlite3 db $filename execsql { CREATE TABLE x1(x); INSERT INTO x1 VALUES('Charles'); INSERT INTO x1 VALUES('James'); INSERT INTO x1 VALUES('Mary'); SELECT * FROM x1; } } {Charles James Mary} do_test pager1-8.$tn.2 { sqlite3 db2 $filename catchsql { SELECT * FROM x1 } db2 } {1 {no such table: x1}} do_execsql_test pager1-8.$tn.3 { BEGIN; INSERT INTO x1 VALUES('William'); INSERT INTO x1 VALUES('Anne'); ROLLBACK; } {} } finish_test |
Changes to test/pager2.test.
︙ | ︙ | |||
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | tv devchar safe_append } { set s 4096 } { set s 4096 set sql { PRAGMA journal_mode = WAL } } { set s 8192 set sql { PRAGMA synchronous = off } }] { incr otn set sql "" tv devchar {} | > > > | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | tv devchar safe_append } { set s 4096 } { set s 4096 set sql { PRAGMA journal_mode = WAL } } { set s 4096 set sql { PRAGMA auto_vacuum = 1 } } { set s 8192 set sql { PRAGMA synchronous = off } }] { incr otn set sql "" tv devchar {} |
︙ | ︙ | |||
108 109 110 111 112 113 114 115 | PRAGMA integrity_check; } [list $x ok] } } } db close tv delete | < | 111 112 113 114 115 116 117 118 119 | PRAGMA integrity_check; } [list $x ok] } } } db close tv delete finish_test |