From 93e931a6b1af326f81f725581d581ca3b3a4634c Mon Sep 17 00:00:00 2001 From: glaszig Date: Thu, 1 Oct 2020 02:50:52 +0200 Subject: [PATCH 1/2] drop ruby 2.4 as it reached eol --- .github/workflows/ruby.yml | 2 +- .ruby-version | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .ruby-version diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8726567..ef4c7c8 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby: [ '2.4.x', '2.5.x', '2.6.x', '2.7.x' ] + ruby: [ '2.5.x', '2.6.x', '2.7.x' ] steps: - name: Install memcache run: | diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..ecd7ee5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.8 From b56952506047d70cb1754423f287d27b2586cc77 Mon Sep 17 00:00:00 2001 From: glaszig Date: Thu, 1 Oct 2020 03:44:58 +0200 Subject: [PATCH 2/2] append default port to server addresses amnesia crashed when trying to fetch results for a server without port number because dalli always appends the default port to addresses. --- config.ru | 2 +- lib/amnesia/host.rb | 8 +++++++- spec/amnesia_spec.rb | 7 ++++++- spec/spec_helper.rb | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config.ru b/config.ru index da96b24..1265d15 100644 --- a/config.ru +++ b/config.ru @@ -6,5 +6,5 @@ require 'amnesia' Encoding.default_internal = 'utf-8' Encoding.default_external = 'utf-8' -use Amnesia::Application, hosts: ['localhost:11211', 'example.local:10987'] +use Amnesia::Application, hosts: ['localhost', 'example.local:10987'] run Sinatra::Application diff --git a/lib/amnesia/host.rb b/lib/amnesia/host.rb index e7fda25..64b5028 100644 --- a/lib/amnesia/host.rb +++ b/lib/amnesia/host.rb @@ -5,8 +5,14 @@ class Host FLOAT_STATS = %w[ rusage_user rusage_system ] STRING_STATS = %w[ version libevent ] + def self.normalize_address address + return "#{address}:#{Dalli::Server::DEFAULT_PORT}" unless address.include? ":" + + address + end + def initialize(address) - @address = address + @address = self.class.normalize_address address end def alive? diff --git a/spec/amnesia_spec.rb b/spec/amnesia_spec.rb index 322ede2..f8974c2 100644 --- a/spec/amnesia_spec.rb +++ b/spec/amnesia_spec.rb @@ -21,10 +21,15 @@ end it "should respond to /:host" do - get "/127.0.0.1:11211" + get "/localhost:11211" expect(last_response.status).to eq 200 end + it "should respond to /:host without port with not found" do + get "/localhost" + expect(last_response.status).to eq 404 + end + it "should not display unknown host" do get "/unknown-host" expect(last_response.status).to eq 404 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b9536ff..b55a83c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ ENV['RACK_ENV'] ||= 'test' ENV['AMNESIA_CREDS'] ||= 'admin:amnesia' +ENV['MEMCACHE_SERVERS'] ||= 'localhost' require 'rack/test' require 'amnesia'