manydb.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # 2005 October 3
  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.
  12. #
  13. # This file implements tests the ability of the library to open
  14. # many different databases at the same time without leaking memory.
  15. #
  16. # $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. set N 300
  20. # if we're using proxy locks, we use 5 filedescriptors for a db
  21. # that is open and in the middle of writing changes, normally
  22. # sqlite uses 3 (proxy locking adds the conch and the local lock)
  23. set using_proxy 0
  24. foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
  25. set using_proxy value
  26. }
  27. set num_fd_per_openwrite_db 3
  28. if {$using_proxy>0} {
  29. set num_fd_per_openwrite_db 5
  30. }
  31. # First test how many file descriptors are available for use. To open a
  32. # database for writing SQLite requires 3 file descriptors (the database, the
  33. # journal and the directory).
  34. set filehandles {}
  35. catch {
  36. for {set i 0} {$i<($N * 3)} {incr i} {
  37. lappend filehandles [open testfile.1 w]
  38. }
  39. }
  40. foreach fd $filehandles {
  41. close $fd
  42. }
  43. catch {
  44. forcedelete testfile.1
  45. }
  46. set N [expr $i / $num_fd_per_openwrite_db]
  47. # Create a bunch of random database names
  48. #
  49. unset -nocomplain dbname
  50. unset -nocomplain used
  51. for {set i 0} {$i<$N} {incr i} {
  52. while 1 {
  53. set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db
  54. if {[info exists used($name)]} continue
  55. set dbname($i) $name
  56. set used($name) $i
  57. break
  58. }
  59. }
  60. # Create a bunch of databases
  61. #
  62. for {set i 0} {$i<$N} {incr i} {
  63. do_test manydb-1.$i {
  64. sqlite3 db$i $dbname($i)
  65. execsql {
  66. CREATE TABLE t1(a,b);
  67. BEGIN;
  68. INSERT INTO t1 VALUES(1,2);
  69. } db$i
  70. } {}
  71. }
  72. # Finish the transactions
  73. #
  74. for {set i 0} {$i<$N} {incr i} {
  75. do_test manydb-2.$i {
  76. execsql {
  77. COMMIT;
  78. SELECT * FROM t1;
  79. } db$i
  80. } {1 2}
  81. }
  82. # Close the databases and erase the files.
  83. #
  84. for {set i 0} {$i<$N} {incr i} {
  85. do_test manydb-3.$i {
  86. db$i close
  87. forcedelete $dbname($i)
  88. } {}
  89. }
  90. finish_test