1
0

tkt3093.test 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # 2008 May 2
  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. # Ticket #3093
  13. #
  14. # Verify that a busy callback waiting on a reserved lock resolves
  15. # once the lock clears.
  16. #
  17. # $Id: tkt3093.test,v 1.2 2008/05/02 14:23:55 drh Exp $
  18. #
  19. set testdir [file dirname $argv0]
  20. source $testdir/tester.tcl
  21. # Set up a test database
  22. #
  23. do_test tkt3093.1 {
  24. db eval {
  25. CREATE TABLE t1(x);
  26. INSERT INTO t1 VALUES(1);
  27. SELECT * FROM t1
  28. }
  29. } {1}
  30. # Establish a separate, independent connection to that database.
  31. #
  32. do_test tkt3093.2 {
  33. catch {sqlite3_enable_shared_cache 0}
  34. sqlite3 db2 test.db
  35. db2 eval {
  36. SELECT * FROM t1
  37. }
  38. } {1}
  39. # Make sure that clearing a lock allows a pending request for
  40. # a reserved lock to continue.
  41. #
  42. do_test tkt3093.3 {
  43. # This will be the busy callback for connection db2. On the first
  44. # busy callback, commit the transaction in db. This should clear
  45. # the lock so that there should not be a second callback. If the
  46. # busy handler is called a second time, then fail so that we get
  47. # timeout.
  48. proc busy_callback {cnt} {
  49. if {$cnt==0} {
  50. db eval COMMIT
  51. return 0
  52. } else {
  53. return 1
  54. }
  55. }
  56. db2 busy ::busy_callback
  57. # Start a write transaction on db.
  58. db eval {
  59. BEGIN;
  60. INSERT INTO t1 VALUES(2);
  61. }
  62. # Attempt to modify the database on db2
  63. catchsql {
  64. UPDATE t1 SET x=x+1;
  65. } db2
  66. } {0 {}}
  67. # Verify that everything worked as expected. The db transaction should
  68. # have gone first and added entry 2. Then the db2 transaction would have
  69. # run and added one to each entry.
  70. #
  71. do_test tkt3093.4 {
  72. db eval {SELECT * FROM t1}
  73. } {2 3}
  74. do_test tkt3093.5 {
  75. db2 eval {SELECT * FROM t1}
  76. } {2 3}
  77. db2 close
  78. finish_test