Sha256: e5b3f221a8ce983bcfa2ffb4d8715770f2a2739f1e0893e3e71e718ed2700e5b

Contents?: true

Size: 1.18 KB

Versions: 27

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require_relative '../test_helper'
require 'logster/cache'

class TestCache < Minitest::Test
  def setup
    @cache = Logster::Cache.new(5)
  end

  def test_cache_works
    prc = Proc.new do |key, value|
      @cache.fetch(key) do
        value
      end
    end
    value = "I should be retured"
    assert_equal(value, prc.call(:key1, value))
    cached_value = value
    value = "I shouldn't be returned"
    assert_equal(cached_value, prc.call(:key1, value))
    value2 = "value for key2"
    assert_equal(value2, prc.call(:key2, value2))

    value = value2 = "Now I should be returned"
    Process.stub :clock_gettime,  Process.clock_gettime(Process::CLOCK_MONOTONIC) + 6 do
      assert_equal(value, prc.call(:key1, value))
      assert_equal(value2, prc.call(:key2, value2))
    end
  end

  def test_cache_can_be_cleared
    value = "cached"
    prc = Proc.new do |key, val|
      @cache.fetch(key) { val }
    end
    assert_equal(value, prc.call(:key1, value))
    assert_equal("v2", prc.call(:key2, "v2"))

    value = "new value"
    @cache.clear(:key1)
    assert_equal(value, prc.call(:key1, value))
    assert_equal("v2", prc.call(:key2, "v2.2"))
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
logster-2.12.2 test/logster/test_cache.rb
logster-2.12.1 test/logster/test_cache.rb
logster-2.11.4 test/logster/test_cache.rb
logster-2.11.3 test/logster/test_cache.rb
logster-2.11.2 test/logster/test_cache.rb
logster-2.11.1 test/logster/test_cache.rb
logster-2.11.0 test/logster/test_cache.rb
logster-2.10.1 test/logster/test_cache.rb
logster-2.10.0 test/logster/test_cache.rb
logster-2.9.8 test/logster/test_cache.rb
logster-2.9.7 test/logster/test_cache.rb
logster-2.9.6 test/logster/test_cache.rb
logster-2.9.5 test/logster/test_cache.rb
logster-2.9.4 test/logster/test_cache.rb
logster-2.9.3 test/logster/test_cache.rb
logster-2.9.2 test/logster/test_cache.rb
logster-2.9.1 test/logster/test_cache.rb
logster-2.9.0 test/logster/test_cache.rb
logster-2.8.0 test/logster/test_cache.rb
logster-2.7.1 test/logster/test_cache.rb