Class: TC_Integration_Pending

Inherits:
SQLite3::TestCase show all
Defined in:
lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb,
lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_pending.rb

Instance Method Summary collapse

Methods inherited from SQLite3::TestCase

#assert_nothing_raised

Instance Method Details

#setupObject



7
8
9
10
11
12
13
14
15
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb', line 7

def setup
  @db = SQLite3::Database.new("test.db")
  @db.transaction do
    @db.execute "create table foo ( a integer primary key, b text )"
    @db.execute "insert into foo ( b ) values ( 'foo' )"
    @db.execute "insert into foo ( b ) values ( 'bar' )"
    @db.execute "insert into foo ( b ) values ( 'baz' )"
  end
end

#teardownObject



17
18
19
20
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb', line 17

def teardown
  @db.close
  File.delete( "test.db" )
end

#test_busy_handler_impatientObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb', line 55

def test_busy_handler_impatient
  busy = Mutex.new
  busy.lock
  handler_call_count = 0

  t = Thread.new do
    begin
      db2 = SQLite3::Database.open( "test.db" )
      db2.transaction( :exclusive ) do
        busy.lock
      end
    ensure
      db2.close if db2
    end
  end
  sleep 1

  @db.busy_handler do
    handler_call_count += 1
    false
  end

  assert_raise( SQLite3::BusyException ) do
    @db.execute "insert into foo (b) values ( 'from 2' )"
  end

  busy.unlock
  t.join

  assert_equal 1, handler_call_count
end

#test_busy_handler_outwaitObject



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
48
49
50
51
52
53
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb', line 22

def test_busy_handler_outwait
  skip("not working in 1.9") if RUBY_VERSION >= '1.9'

  busy = Mutex.new
  busy.lock
  handler_call_count = 0

  t = Thread.new(busy) do |locker|
    begin
      db2 = SQLite3::Database.open( "test.db" )
      db2.transaction( :exclusive ) do
        locker.lock
      end
    ensure
      db2.close if db2
    end
  end

  @db.busy_handler do |data,count|
    handler_call_count += 1
    busy.unlock
    true
  end

  assert_nothing_raised do
    @db.execute "insert into foo (b) values ( 'from 2' )"
  end

  t.join

  assert_equal 1, handler_call_count
end

#test_busy_timeoutObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb', line 87

def test_busy_timeout
  @db.busy_timeout 1000
  busy = Mutex.new
  busy.lock

  t = Thread.new do
    begin
      db2 = SQLite3::Database.open( "test.db" )
      db2.transaction( :exclusive ) do
        busy.lock
      end
    ensure
      db2.close if db2
    end
  end

  sleep 1
  time = Benchmark.measure do
    assert_raise( SQLite3::BusyException ) do
      @db.execute "insert into foo (b) values ( 'from 2' )"
    end
  end

  busy.unlock
  t.join

  assert time.real*1000 >= 1000
end