| OLD | NEW |
| 1 # 2009 January 30 | 1 # 2009 January 30 |
| 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 #*********************************************************************** |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 do_test backup_ioerr-1.1 { | 53 do_test backup_ioerr-1.1 { |
| 54 populate_database db | 54 populate_database db |
| 55 set nPage [expr {[file size test.db] / 1024}] | 55 set nPage [expr {[file size test.db] / 1024}] |
| 56 expr {$nPage>130 && $nPage<160} | 56 expr {$nPage>130 && $nPage<160} |
| 57 } {1} | 57 } {1} |
| 58 do_test backup_ioerr-1.2 { | 58 do_test backup_ioerr-1.2 { |
| 59 expr {[file size test.db] > $sqlite_pending_byte} | 59 expr {[file size test.db] > $sqlite_pending_byte} |
| 60 } {1} | 60 } {1} |
| 61 do_test backup_ioerr-1.3 { | 61 do_test backup_ioerr-1.3 { |
| 62 db close | 62 db close |
| 63 file delete -force test.db | 63 forcedelete test.db |
| 64 } {} | 64 } {} |
| 65 | 65 |
| 66 # Turn off IO error simulation. | 66 # Turn off IO error simulation. |
| 67 # | 67 # |
| 68 proc clear_ioerr_simulation {} { | 68 proc clear_ioerr_simulation {} { |
| 69 set ::sqlite_io_error_hit 0 | 69 set ::sqlite_io_error_hit 0 |
| 70 set ::sqlite_io_error_hardhit 0 | 70 set ::sqlite_io_error_hardhit 0 |
| 71 set ::sqlite_io_error_pending 0 | 71 set ::sqlite_io_error_pending 0 |
| 72 set ::sqlite_io_error_persist 0 | 72 set ::sqlite_io_error_persist 0 |
| 73 } | 73 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 # | 108 # |
| 109 # * If an IO error occurs while updating the backup, the write | 109 # * If an IO error occurs while updating the backup, the write |
| 110 # operation should proceed normally. The error should be reported | 110 # operation should proceed normally. The error should be reported |
| 111 # from the next call to backup_step() (in step 5 of this test | 111 # from the next call to backup_step() (in step 5 of this test |
| 112 # procedure). | 112 # procedure). |
| 113 # | 113 # |
| 114 # 5) Step the backup process to finish the backup. If an IO error is | 114 # 5) Step the backup process to finish the backup. If an IO error is |
| 115 # reported, then the backup process is concluded with a call to | 115 # reported, then the backup process is concluded with a call to |
| 116 # backup_finish(). | 116 # backup_finish(). |
| 117 # | 117 # |
| 118 # Test that if an IO error occurs, or if one occured while updating | 118 # Test that if an IO error occurs, or if one occurred while updating |
| 119 # the backup database during step 4, then the conditions listed | 119 # the backup database during step 4, then the conditions listed |
| 120 # under step 3 are all true. | 120 # under step 3 are all true. |
| 121 # | 121 # |
| 122 # 6) Finish the backup process. | 122 # 6) Finish the backup process. |
| 123 # | 123 # |
| 124 # * If the backup succeeds (backup_finish() returns SQLITE_OK), then | 124 # * If the backup succeeds (backup_finish() returns SQLITE_OK), then |
| 125 # the contents of the backup database should match that of the | 125 # the contents of the backup database should match that of the |
| 126 # source database. | 126 # source database. |
| 127 # | 127 # |
| 128 # * If the backup fails (backup_finish() returns other than SQLITE_OK), | 128 # * If the backup fails (backup_finish() returns other than SQLITE_OK), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 148 foreach zSetupBak [list "" {populate_database ddb 1}] { | 148 foreach zSetupBak [list "" {populate_database ddb 1}] { |
| 149 | 149 |
| 150 incr iTest | 150 incr iTest |
| 151 set bStop 0 | 151 set bStop 0 |
| 152 for {set iError 1} {$bStop == 0} {incr iError} { | 152 for {set iError 1} {$bStop == 0} {incr iError} { |
| 153 # Disable IO error simulation. | 153 # Disable IO error simulation. |
| 154 clear_ioerr_simulation | 154 clear_ioerr_simulation |
| 155 | 155 |
| 156 catch { ddb close } | 156 catch { ddb close } |
| 157 catch { sdb close } | 157 catch { sdb close } |
| 158 catch { file delete -force test.db } | 158 catch { forcedelete test.db } |
| 159 catch { file delete -force bak.db } | 159 catch { forcedelete bak.db } |
| 160 | 160 |
| 161 # Open the source and destination databases. | 161 # Open the source and destination databases. |
| 162 sqlite3 sdb test.db | 162 sqlite3 sdb test.db |
| 163 sqlite3 ddb bak.db | 163 sqlite3 ddb bak.db |
| 164 | 164 |
| 165 # Step 1: Populate the source and destination databases. | 165 # Step 1: Populate the source and destination databases. |
| 166 populate_database sdb | 166 populate_database sdb |
| 167 ddb eval "PRAGMA page_size = $iDestPagesize" | 167 ddb eval "PRAGMA page_size = $iDestPagesize" |
| 168 ddb eval "PRAGMA cache_size = 10" | 168 ddb eval "PRAGMA cache_size = 10" |
| 169 eval $zSetupBak | 169 eval $zSetupBak |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 # No IO error was encountered during step 3. Check that backup_step() | 207 # No IO error was encountered during step 3. Check that backup_step() |
| 208 # returned SQLITE_OK before proceding. | 208 # returned SQLITE_OK before proceding. |
| 209 do_test backup_ioerr-$iTest.$iError.6 { | 209 do_test backup_ioerr-$iTest.$iError.6 { |
| 210 expr {$rc eq "SQLITE_OK"} | 210 expr {$rc eq "SQLITE_OK"} |
| 211 } {1} | 211 } {1} |
| 212 | 212 |
| 213 # Step 4: Write to the source database. | 213 # Step 4: Write to the source database. |
| 214 set rc [catchsql { UPDATE t1 SET b = randstr(1000,1000) WHERE a < 50 } sdb] | 214 set rc [catchsql { UPDATE t1 SET b = randstr(1000,1000) WHERE a < 50 } sdb] |
| 215 | 215 |
| 216 if {[lindex $rc 0] && $::sqlite_io_error_persist==0} { | 216 if {[lindex $rc 0] && $::sqlite_io_error_persist==0} { |
| 217 # The IO error occured while updating the source database. In this | 217 # The IO error occurred while updating the source database. In this |
| 218 # case the backup should be able to continue. | 218 # case the backup should be able to continue. |
| 219 set rc [B step 5000] | 219 set rc [B step 5000] |
| 220 if { $rc != "SQLITE_IOERR_UNLOCK" } { | 220 if { $rc != "SQLITE_IOERR_UNLOCK" } { |
| 221 do_test backup_ioerr-$iTest.$iError.7 { | 221 do_test backup_ioerr-$iTest.$iError.7 { |
| 222 list [B step 5000] [B finish] | 222 list [B step 5000] [B finish] |
| 223 } {SQLITE_DONE SQLITE_OK} | 223 } {SQLITE_DONE SQLITE_OK} |
| 224 | 224 |
| 225 clear_ioerr_simulation | 225 clear_ioerr_simulation |
| 226 test_contents backup_ioerr-$iTest.$iError.8 ddb main sdb main | 226 test_contents backup_ioerr-$iTest.$iError.8 ddb main sdb main |
| 227 integrity_check backup_ioerr-$iTest.$iError.9 ddb | 227 integrity_check backup_ioerr-$iTest.$iError.9 ddb |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 test_contents backup_ioerr-$iTest.$iError.18 ddb main sdb main | 278 test_contents backup_ioerr-$iTest.$iError.18 ddb main sdb main |
| 279 integrity_check backup_ioerr-$iTest.$iError.19 ddb | 279 integrity_check backup_ioerr-$iTest.$iError.19 ddb |
| 280 | 280 |
| 281 set bStop [expr $::sqlite_io_error_pending<=0] | 281 set bStop [expr $::sqlite_io_error_pending<=0] |
| 282 }}}} | 282 }}}} |
| 283 | 283 |
| 284 catch { sdb close } | 284 catch { sdb close } |
| 285 catch { ddb close } | 285 catch { ddb close } |
| 286 finish_test | 286 finish_test |
| OLD | NEW |