OLD | NEW |
1 # 2015 Aug 8 | 1 # 2015 Aug 8 |
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 if {![info exists testdir]} { | 13 if {![info exists testdir]} { |
14 set testdir [file join [file dirname [info script]] .. .. test] | 14 set testdir [file join [file dirname [info script]] .. .. test] |
15 } | 15 } |
16 source $testdir/tester.tcl | 16 source $testdir/tester.tcl |
17 | 17 |
| 18 proc check_prestep_state {target state} { |
| 19 set oal_exists [file exists $target-oal] |
| 20 set wal_exists [file exists $target-wal] |
| 21 set progress [rbu progress] |
| 22 |
| 23 if {($progress==0 && $state!="oal" && $state!="done") |
| 24 || ($oal_exists && $wal_exists) |
| 25 || ($progress>0 && $state=="oal" && (!$oal_exists || $wal_exists)) |
| 26 || ($state=="move" && (!$oal_exists || $wal_exists)) |
| 27 || ($state=="checkpoint" && ($oal_exists || !$wal_exists)) |
| 28 || ($state=="done" && ($oal_exists && $progress!=0)) |
| 29 } { |
| 30 error "B: state=$state progress=$progress oal=$oal_exists wal=$wal_exists" |
| 31 } |
| 32 } |
| 33 |
| 34 proc check_poststep_state {rc target state} { |
| 35 if {$rc=="SQLITE_OK" || $rc=="SQLITE_DONE"} { |
| 36 set oal_exists [file exists $target-oal] |
| 37 set wal_exists [file exists $target-wal] |
| 38 if {$state=="move" && ($oal_exists || !$wal_exists)} { |
| 39 error "A: state=$state progress=$progress oal=$oal_exists wal=$wal_exists" |
| 40 } |
| 41 } |
| 42 } |
| 43 |
18 # Run the RBU in file $rbu on target database $target until completion. | 44 # Run the RBU in file $rbu on target database $target until completion. |
19 # | 45 # |
20 proc run_rbu {target rbu} { | 46 proc run_rbu {target rbu} { |
21 sqlite3rbu rbu $target $rbu | 47 sqlite3rbu rbu $target $rbu |
22 while 1 { | 48 while 1 { |
| 49 set state [rbu state] |
| 50 |
| 51 check_prestep_state $target $state |
23 set rc [rbu step] | 52 set rc [rbu step] |
| 53 check_poststep_state $rc $target $state |
| 54 |
24 if {$rc!="SQLITE_OK"} break | 55 if {$rc!="SQLITE_OK"} break |
25 } | 56 } |
26 rbu close | 57 rbu close |
27 } | 58 } |
28 | 59 |
29 proc step_rbu {target rbu} { | 60 proc step_rbu {target rbu} { |
30 while 1 { | 61 while 1 { |
31 sqlite3rbu rbu $target $rbu | 62 sqlite3rbu rbu $target $rbu |
| 63 set state [rbu state] |
| 64 check_prestep_state $target $state |
32 set rc [rbu step] | 65 set rc [rbu step] |
| 66 check_poststep_state $rc $target $state |
33 rbu close | 67 rbu close |
34 if {$rc != "SQLITE_OK"} break | 68 if {$rc != "SQLITE_OK"} break |
35 } | 69 } |
36 set rc | 70 set rc |
37 } | 71 } |
38 | 72 |
| 73 proc do_rbu_vacuum_test {tn step} { |
| 74 uplevel [list do_test $tn.1 { |
| 75 if {$step==0} { sqlite3rbu_vacuum rbu test.db state.db } |
| 76 while 1 { |
| 77 if {$step==1} { sqlite3rbu_vacuum rbu test.db state.db } |
| 78 set state [rbu state] |
| 79 check_prestep_state test.db $state |
| 80 set rc [rbu step] |
| 81 check_poststep_state $rc test.db $state |
| 82 if {$rc!="SQLITE_OK"} break |
| 83 if {$step==1} { rbu close } |
| 84 } |
| 85 rbu close |
| 86 } {SQLITE_DONE}] |
| 87 |
| 88 uplevel [list do_execsql_test $tn.2 { |
| 89 PRAGMA integrity_check |
| 90 } ok] |
| 91 } |
| 92 |
OLD | NEW |