diskfull.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # 2001 October 12
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. # This file implements regression tests for SQLite library. The
  12. # focus of this file is testing for correct handling of disk full
  13. # errors.
  14. #
  15. # $Id: diskfull.test,v 1.8 2008/07/12 14:52:20 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. set sqlite_io_error_persist 0
  19. set sqlite_io_error_hit 0
  20. set sqlite_io_error_pending 0
  21. do_test diskfull-1.1 {
  22. execsql {
  23. CREATE TABLE t1(x);
  24. INSERT INTO t1 VALUES(randstr(1000,1000));
  25. INSERT INTO t1 SELECT * FROM t1;
  26. INSERT INTO t1 SELECT * FROM t1;
  27. INSERT INTO t1 SELECT * FROM t1;
  28. INSERT INTO t1 SELECT * FROM t1;
  29. CREATE INDEX t1i1 ON t1(x);
  30. CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1;
  31. CREATE INDEX t2i1 ON t2(b);
  32. }
  33. } {}
  34. set sqlite_diskfull_pending 0
  35. integrity_check diskfull-1.2
  36. do_test diskfull-1.3 {
  37. set sqlite_diskfull_pending 1
  38. catchsql {
  39. INSERT INTO t1 SELECT * FROM t1;
  40. }
  41. } {1 {database or disk is full}}
  42. set sqlite_diskfull_pending 0
  43. integrity_check diskfull-1.4
  44. do_test diskfull-1.5 {
  45. set sqlite_diskfull_pending 1
  46. catchsql {
  47. DELETE FROM t1;
  48. }
  49. } {1 {database or disk is full}}
  50. set sqlite_diskfull_pending 0
  51. set sqlite_io_error_hit 0
  52. integrity_check diskfull-1.6
  53. proc do_diskfull_test {prefix sql} {
  54. set ::go 1
  55. set ::sql $sql
  56. set ::i 1
  57. while {$::go} {
  58. incr ::i
  59. do_test ${prefix}.$::i.1 {
  60. set ::sqlite_diskfull_pending $::i
  61. set ::sqlite_diskfull 0
  62. set r [catchsql $::sql]
  63. if {!$::sqlite_diskfull} {
  64. set r {1 {database or disk is full}}
  65. set ::go 0
  66. }
  67. if {$r=="1 {disk I/O error}"} {
  68. set r {1 {database or disk is full}}
  69. }
  70. set r
  71. } {1 {database or disk is full}}
  72. set ::sqlite_diskfull_pending 0
  73. db close
  74. sqlite3 db test.db
  75. integrity_check ${prefix}.$::i.2
  76. }
  77. }
  78. do_diskfull_test diskfull-2 VACUUM
  79. # db close
  80. # forcedelete test.db
  81. # forcedelete test.db-journal
  82. # sqlite3 db test.db
  83. #
  84. # do_test diskfull-3.1 {
  85. # execsql {
  86. # PRAGMA default_cache_size = 10;
  87. # CREATE TABLE t3(a, b, UNIQUE(a, b));
  88. # INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
  89. # INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
  90. # INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
  91. # INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
  92. # INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
  93. # INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
  94. # INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
  95. # INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
  96. # UPDATE t3
  97. # SET b = (SELECT a FROM t3 WHERE rowid = (SELECT max(rowid)-1 FROM t3))
  98. # WHERE rowid = (SELECT max(rowid) FROM t3);
  99. # PRAGMA cache_size;
  100. # }
  101. # } {10}
  102. #
  103. # do_diskfull_test diskfull-3.2 {
  104. # BEGIN;
  105. # INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
  106. # UPDATE t3 SET a = b;
  107. # COMMIT;
  108. # }
  109. finish_test