Skip to content

Commit

Permalink
Check if memcached is running during memcache spec, and fail if not r…
Browse files Browse the repository at this point in the history
…unning (#591)

* Check if memcached is running during memcache spec, and fail if not running

I was trying to run the test suite locally, and it failed here because I
didn't have memcached running (yet):

  1) Rack::MiniProfiler::MemcacheStore page struct storage can store a PageStruct and retrieve it
     Failure/Error: @client.set("#{@Prefix}#{page_struct[:id]}", Marshal::dump(page_struct), @expires_in_seconds)

     Dalli::RingError:
       No server available
     # ./lib/mini_profiler/storage/memcache_store.rb:22:in `save'
     # ./spec/lib/storage/memcache_store_spec.rb:17:in `block (4 levels) in <top (required)>'

This adds a `alive?` method that the spec can check, and give more
specific information to the user. I've also included a
docker-compose.yml to give a one-liner to start memcached.

* Don't bother with a docker-compose at this point. Suggest using docker directly
  • Loading branch information
technicalpickles committed Dec 4, 2023
1 parent 570809b commit 88cfbb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/mini_profiler/storage/memcache_store.rb
Expand Up @@ -18,6 +18,15 @@ def initialize(args = nil)
@expires_in_seconds = args[:expires_in] || EXPIRES_IN_SECONDS
end

def alive?
begin
@client.alive!
true
rescue Dalli::RingError
false
end
end

def save(page_struct)
@client.set("#{@prefix}#{page_struct[:id]}", Marshal::dump(page_struct), @expires_in_seconds)
end
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/storage/memcache_store_spec.rb
Expand Up @@ -6,6 +6,9 @@

before do
@store = Rack::MiniProfiler::MemcacheStore.new
unless @store.alive?
fail 'Memcached does not appear to be running on localhost:11211. Use your favorite package manager to install and run it, use Docker with: `docker run -it --rm memcached`'
end
end

describe 'storage' do
Expand Down

0 comments on commit 88cfbb4

Please sign in to comment.