sessionfault3.test 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # 2016 October 6
  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. #
  12. # The focus of this file is testing the session module.
  13. #
  14. if {![info exists testdir]} {
  15. set testdir [file join [file dirname [info script]] .. .. test]
  16. }
  17. source [file join [file dirname [info script]] session_common.tcl]
  18. source $testdir/tester.tcl
  19. ifcapable !session {finish_test; return}
  20. set testprefix sessionfault3
  21. do_execsql_test 1.0 {
  22. CREATE TABLE t1(a, b, PRIMARY KEY(a));
  23. INSERT INTO t1 VALUES(1, 2);
  24. INSERT INTO t1 VALUES(3, 4);
  25. INSERT INTO t1 VALUES('five', 'six');
  26. }
  27. set C1 [changeset_from_sql {
  28. INSERT INTO t1 VALUES('seven', 'eight');
  29. UPDATE t1 SET b=6 WHERE a='five';
  30. DELETE FROM t1 WHERE a=1;
  31. }]
  32. do_execsql_test 1.1 {
  33. ALTER TABLE t1 ADD COLUMN d DEFAULT 123;
  34. ALTER TABLE t1 ADD COLUMN e DEFAULT 'string';
  35. }
  36. set C2 [changeset_from_sql {
  37. UPDATE t1 SET e='new value' WHERE a='seven';
  38. INSERT INTO t1 VALUES(0, 0, 0, 0);
  39. }]
  40. do_faultsim_test 1 -faults oom* -prep {
  41. sqlite3changegroup G
  42. } -body {
  43. G schema db main
  44. G add $::C1
  45. G add $::C2
  46. G output
  47. set {} {}
  48. } -test {
  49. catch { G delete }
  50. faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
  51. }
  52. #-------------------------------------------------------------------------
  53. reset_db
  54. do_execsql_test 2.0 {
  55. CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
  56. INSERT INTO t1 VALUES(1, 'one');
  57. INSERT INTO t1 VALUES(2, 'two');
  58. ALTER TABLE t1 ADD COLUMN c DEFAULT 'abcdefghijklmnopqrstuvwxyz';
  59. }
  60. faultsim_save_and_close
  61. do_faultsim_test 2 -faults oom-t* -prep {
  62. faultsim_restore_and_reopen
  63. db eval {SELECT * FROM sqlite_schema}
  64. } -body {
  65. sqlite3session S db main
  66. S attach *
  67. execsql {
  68. DELETE FROM t1 WHERE a = 1;
  69. }
  70. } -test {
  71. faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
  72. catch { S delete }
  73. }
  74. finish_test