<commit_before>require 'spec_helper'

describe Mongo::Lock do

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

  describe '#extend_by' do

    context "when a time is provided" do

      it "extends the lock" do
        lock.acquire
        lock.extend_by 60
        expect(collection.find(owner: 'spence', key: 'my_lock').first['expires_at']).to be_within(1.second).of(60.seconds.from_now)
      end

      it "returns true" do
        lock.acquire
        expect(lock.extend_by 50).to be_true
      end

    end

    context "when the lock has expired" do

      it "returns false" do
        lock.acquire
        sleep 0.02
        expect(lock.extend_by 10).to be_false
      end

    end

    context "when the lock has not been aquired yet" do

      it "returns false" do
        lock
        expect(lock.extend_by 10).to be_false
      end

    end

    context "when the lock has been released" do

      it "returns false" do
        lock.acquire
        lock.release
        expect(lock.extend_by 10).to be_false
      end

    end

    context "when the raise option is set to true" do

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

      context "and the lock has expired" do<commit_msg>Made timing on a test a bit more leaniant<commit_after>require 'spec_helper'

describe Mongo::Lock do

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

  describe '#extend_by' do

    context "when a time is provided" do

      it "extends the lock" do
        lock.acquire
        lock.extend_by 60
        expect(collection.find(owner: 'spence', key: 'my_lock').first['expires_at']).to be_within(1.second).of(60.seconds.from_now)
      end

      it "returns true" do
        lock.acquire
        expect(lock.extend_by 50).to be_true
      end

    end

    context "when the lock has expired" do

      it "returns false" do
        lock.acquire
        sleep 0.11
        expect(lock.extend_by 10).to be_false
      end

    end

    context "when the lock has not been aquired yet" do

      it "returns false" do
        lock
        expect(lock.extend_by 10).to be_false
      end

    end

    context "when the lock has been released" do

      it "returns false" do
        lock.acquire
        lock.release
        expect(lock.extend_by 10).to be_false
      end

    end

    context "when the raise option is set to true" do

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

      context "and the lock has expired" do
{'fraction_non_alphanumeric': 0.09422936449963477, 'fraction_numerical': 0.02410518626734843, 'mean_word_length': 2.336175395858709, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1167523', 'n_tokens_mistral': 955, 'n_tokens_neox': 851, 'n_words': 283}