Sha256: 1cc1abd676a842446211193d192ee0b486ff40281070bf05f67bf35c6063b7a7

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

shared_examples "MongoLock driver that can find if a lock is acquired" do

  describe Mongo::Lock do

    describe '#acquired?' do

      let(:lock) { Mongo::Lock.new 'my_lock', owner: 'spence', timeout_in: 0.01, frequency: 0.01 }

      context "when the lock has been acquired" do

        it "returns true" do
          lock.acquire
          expect(lock.acquired?).to be_true
        end

      end

      context "when the lock hasn't been acquired" do

        it "returns false" do
          my_collection.insert key: 'my_lock', owner: 'tobie', expires_at: 1.minute.from_now
          lock.acquire
          expect(lock.acquired?).to be_false
        end

      end

      context "when the lock was acquired but has since expired" do

        let(:lock) { Mongo::Lock.new 'my_lock', owner: 'spence', timeout_in: 0.01, frequency: 0.01, expire_in: 0.1 }

        it "returns false" do
          lock.acquire
          sleep 0.2
          expect(lock.acquired?).to be_false
        end

      end

      context "when the lock was acquired but has since been released" do

        it "returns false" do
          my_collection.insert key: 'my_lock', owner: 'tobie', expires_at: 1.minute.ago
          lock.acquire
          lock.release
          expect(lock.acquired?).to be_false
        end

      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongo-lock-1.2.0 spec/examples/acquired_example.rb