test/test_zache.rb in zache-0.13.1 vs test/test_zache.rb in zache-0.13.2

- old
+ new

@@ -1,10 +1,10 @@ # frozen_string_literal: true # (The MIT License) # -# Copyright (c) 2018-2023 Yegor Bugayenko +# Copyright (c) 2018-2024 Yegor Bugayenko # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -30,11 +30,11 @@ Thread.report_on_exception = true # Cache test. # Author:: Yegor Bugayenko (yegor256@gmail.com) -# Copyright:: Copyright (c) 2018-2023 Yegor Bugayenko +# Copyright:: Copyright (c) 2018-2024 Yegor Bugayenko # License:: MIT class ZacheTest < Minitest::Test def test_caches cache = Zache.new(sync: false) first = cache.get(:hey, lifetime: 5) { Random.rand } @@ -132,10 +132,18 @@ cache.clean assert(cache.exists?(:hey) == true) assert(cache.exists?(:bye) == false) end + def test_clean_size + cache = Zache.new + cache.get(:hey, lifetime: 0.01) { Random.rand } + sleep 0.1 + cache.clean + assert(cache.empty?) + end + def test_clean_with_sync_false cache = Zache.new(sync: false) cache.get(:hey) { Random.rand } cache.get(:bye, lifetime: 0.01) { Random.rand } sleep 0.1 @@ -156,15 +164,15 @@ end def test_remove_all_with_threads cache = Zache.new Threads.new(10).assert(100) do |i| - cache.get("hey#{i}".to_sym) { Random.rand } - assert(cache.exists?("hey#{i}".to_sym) == true) + cache.get(:"hey#{i}") { Random.rand } + assert(cache.exists?(:"hey#{i}") == true) cache.remove_all end 10.times do |i| - assert(cache.exists?("hey#{i}".to_sym) == false) + assert(cache.exists?(:"hey#{i}") == false) end end def test_remove_all_with_sync cache = Zache.new