File: test_resource_cleanup.rb

package info (click to toggle)
ruby-sqlite3 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 680 kB
  • sloc: ruby: 4,827; ansic: 1,868; sh: 91; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "helper"

module SQLite3
  # these tests will cause ruby_memcheck to report a leak if we're not cleaning up resources
  class TestResourceCleanup < SQLite3::TestCase
    def test_cleanup_unclosed_database_object
      100.times do
        SQLite3::Database.new(":memory:")
      end
    end

    def test_cleanup_unclosed_statement_object
      100.times do
        db = SQLite3::Database.new(":memory:")
        db.execute("create table foo(text BLOB)")
        db.prepare("select * from foo")
      end
    end

    # # this leaks the result set
    # def test_cleanup_unclosed_resultset_object
    #   db = SQLite3::Database.new(':memory:')
    #   db.execute('create table foo(text BLOB)')
    #   stmt = db.prepare('select * from foo')
    #   stmt.execute
    # end

    # # this leaks the incompletely-closed connection
    # def test_cleanup_discarded_connections
    #   FileUtils.rm_f "test.db"
    #   db = SQLite3::Database.new("test.db")
    #   db.execute("create table posts (title text)")
    #   db.execute("insert into posts (title) values ('hello')")
    #   db.close
    #   100.times do
    #     db = SQLite3::Database.new("test.db")
    #     db.execute("select * from posts limit 1")
    #     stmt = db.prepare("select * from posts")
    #     stmt.execute
    #     stmt.close
    #     db.discard
    #   end
    # ensure
    #   FileUtils.rm_f "test.db"
    # end
  end
end