sequel-pg-locker 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Sequel
2
2
  module Pg
3
3
  module Locker
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -6,16 +6,17 @@ module Sequel
6
6
  module PG
7
7
  module Locker
8
8
  def self.lock(id)
9
- Timeout.timeout(3) { connection["SELECT pg_try_advisory_lock(#{id})"].get }
9
+ db["SELECT pg_try_advisory_lock(#{id})"].get
10
10
  end
11
11
 
12
12
  private
13
13
 
14
- def self.connection
15
- @connection ||= Sequel.connect(ENV['DATABASE_URL'], encoding: "unicode") do |conn|
16
- conn.run("SET synchronous_commit TO 'off'")
17
- conn
18
- end
14
+ def self.db
15
+ @db ||= Sequel.connect(database_url)
16
+ end
17
+
18
+ def self.database_url
19
+ @database_url ||= ENV['DATABASE_URL']
19
20
  end
20
21
  end
21
22
  end
@@ -2,27 +2,23 @@ require 'minitest/autorun'
2
2
 
3
3
  require "sequel-pg-locker"
4
4
 
5
- LOCK_ID = rand(1_000_000)
5
+ ENV['DATABASE_URL'] ||= "postgres://localhost/sequel_pg_locker_test"
6
6
 
7
7
  describe Sequel::PG::Locker do
8
8
  subject { Sequel::PG::Locker }
9
9
 
10
- before do
11
- ENV['DATABASE_URL'] = "postgres://localhost/sequel_pg_locker_test"
12
- end
13
-
14
10
  describe ".lock" do
15
- before do
16
- subject.instance_variable_set(:@connection, nil)
17
- end
18
-
19
11
  it "should provide a lock" do
20
- assert subject.lock(LOCK_ID)
12
+ id = rand(1_000_000)
13
+ subject.instance_variable_set(:@db, nil)
14
+ assert subject.lock(id)
21
15
  end
22
16
 
23
17
  it "should not allow further locking" do
24
- subject.lock(LOCK_ID)
25
- assert !subject.lock(LOCK_ID)
18
+ id = rand(1_000_000)
19
+ assert subject.lock(id)
20
+ subject.instance_variable_set(:@db, nil)
21
+ assert !subject.lock(id)
26
22
  end
27
23
  end
28
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-pg-locker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: