From eb03fdf80bfe07eae1b811c21fa418901da3d75b Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 27 Jan 2022 16:59:01 +0100 Subject: [PATCH 01/11] + make it work with ruby 3.1 by upgrading thin to the latest version and replacing skinny with faye-websocket + allow mailcatcher process to be stopped with SIGINT --- lib/mail_catcher.rb | 8 ++++++- lib/mail_catcher/web/application.rb | 37 ++++++++++++++++------------- mailcatcher.gemspec | 5 ++-- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/mail_catcher.rb b/lib/mail_catcher.rb index a1fd54b3..b933832e 100644 --- a/lib/mail_catcher.rb +++ b/lib/mail_catcher.rb @@ -178,6 +178,12 @@ def run! options=nil # One EventMachine loop... EventMachine.run do + trap("INT") do + EventMachine.add_timer(0) do + quit! + end + end + # Set up an SMTP server to run within EventMachine rescue_port options[:smtp_port] do EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp @@ -187,7 +193,7 @@ def run! options=nil # Let Thin set itself up inside our EventMachine loop # (Skinny/WebSockets just works on the inside) rescue_port options[:http_port] do - Thin::Server.start(options[:http_ip], options[:http_port], Web) + Thin::Server.start(options[:http_ip], options[:http_port], Web, signals: false) puts "==> #{http_url}" end diff --git a/lib/mail_catcher/web/application.rb b/lib/mail_catcher/web/application.rb index 3a2246ff..e7fb07d7 100644 --- a/lib/mail_catcher/web/application.rb +++ b/lib/mail_catcher/web/application.rb @@ -5,14 +5,12 @@ require "uri" require "sinatra" -require "skinny" +require 'faye/websocket' require "mail_catcher/bus" require "mail_catcher/mail" -class Sinatra::Request - include Skinny::Helpers -end +Faye::WebSocket.load_adapter('thin') module MailCatcher module Web @@ -61,21 +59,26 @@ def asset_path(filename) end get "/messages" do - if request.websocket? - request.websocket!( - :on_start => proc do |websocket| - bus_subscription = MailCatcher::Bus.subscribe do |message| - begin - websocket.send_message(JSON.generate(message)) - rescue => exception - MailCatcher.log_exception("Error sending message through websocket", message, exception) - end + env = request.env + if Faye::WebSocket.websocket?(env) + bus_subscription = nil + + ws = Faye::WebSocket.new(env) + ws.on(:open) do |_| + bus_subscription = MailCatcher::Bus.subscribe do |message| + begin + ws.send(JSON.generate(message)) + rescue => exception + MailCatcher.log_exception("Error sending message through websocket", message, exception) end + end + end - websocket.on_close do |*| - MailCatcher::Bus.unsubscribe bus_subscription - end - end) + ws.on(:close) do |_| + MailCatcher::Bus.unsubscribe(bus_subscription) if bus_subscription + end + + ws.rack_response else content_type :json JSON.generate(Mail.messages) diff --git a/mailcatcher.gemspec b/mailcatcher.gemspec index 17fda894..a721e42a 100644 --- a/mailcatcher.gemspec +++ b/mailcatcher.gemspec @@ -37,8 +37,9 @@ Gem::Specification.new do |s| s.add_dependency "rack", "~> 1.5" s.add_dependency "sinatra", "~> 1.2" s.add_dependency "sqlite3", "~> 1.3" - s.add_dependency "thin", "~> 1.5.0" - s.add_dependency "skinny", "~> 0.2.3" + s.add_dependency "thin", "~> 1.8.0" + s.add_dependency "net-smtp", "~> 0.3.0" + s.add_dependency "faye-websocket", "~> 0.11.1" s.add_development_dependency "capybara" s.add_development_dependency "capybara-screenshot" From f1e379d509c5fe203f7495f2ceec86a6024841ce Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 4 Mar 2022 17:02:34 +0100 Subject: [PATCH 02/11] code review changes --- lib/mail_catcher.rb | 6 ------ lib/mail_catcher/web/application.rb | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/mail_catcher.rb b/lib/mail_catcher.rb index b933832e..013778ea 100644 --- a/lib/mail_catcher.rb +++ b/lib/mail_catcher.rb @@ -178,12 +178,6 @@ def run! options=nil # One EventMachine loop... EventMachine.run do - trap("INT") do - EventMachine.add_timer(0) do - quit! - end - end - # Set up an SMTP server to run within EventMachine rescue_port options[:smtp_port] do EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp diff --git a/lib/mail_catcher/web/application.rb b/lib/mail_catcher/web/application.rb index e7fb07d7..d8afa7ba 100644 --- a/lib/mail_catcher/web/application.rb +++ b/lib/mail_catcher/web/application.rb @@ -5,12 +5,12 @@ require "uri" require "sinatra" -require 'faye/websocket' +require "faye/websocket" require "mail_catcher/bus" require "mail_catcher/mail" -Faye::WebSocket.load_adapter('thin') +Faye::WebSocket.load_adapter("thin") module MailCatcher module Web From c17f8765342fdf181bbb14ebfeb82694cb2c10a5 Mon Sep 17 00:00:00 2001 From: Samuel Cochran Date: Sat, 5 Mar 2022 09:28:34 +1100 Subject: [PATCH 03/11] Include testing ruby 3.1 on CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9be56ab9..f94ce223 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0'] + ruby-version: ['2.6', '2.7', '3.0', '3.1'] steps: - uses: actions/checkout@v2 From f71d348d18a2a984b563ec50047566554115f2eb Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 7 Mar 2022 17:20:52 +0100 Subject: [PATCH 04/11] bring back INT signal handling --- lib/mail_catcher.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/mail_catcher.rb b/lib/mail_catcher.rb index 013778ea..b933832e 100644 --- a/lib/mail_catcher.rb +++ b/lib/mail_catcher.rb @@ -178,6 +178,12 @@ def run! options=nil # One EventMachine loop... EventMachine.run do + trap("INT") do + EventMachine.add_timer(0) do + quit! + end + end + # Set up an SMTP server to run within EventMachine rescue_port options[:smtp_port] do EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp From 9140a6077723f428568024c6ee7da7e6da591eca Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 7 Mar 2022 20:21:52 +0100 Subject: [PATCH 05/11] add net-http as dependency constant init warnings --- mailcatcher.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/mailcatcher.gemspec b/mailcatcher.gemspec index a721e42a..85e5e191 100644 --- a/mailcatcher.gemspec +++ b/mailcatcher.gemspec @@ -39,6 +39,7 @@ Gem::Specification.new do |s| s.add_dependency "sqlite3", "~> 1.3" s.add_dependency "thin", "~> 1.8.0" s.add_dependency "net-smtp", "~> 0.3.0" + s.add_dependency "net-http", "~> 0.2.0" s.add_dependency "faye-websocket", "~> 0.11.1" s.add_development_dependency "capybara" From 95872aa6be6c0b5edf76e7505f79629526edbefd Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 20 Apr 2022 13:27:45 +0200 Subject: [PATCH 06/11] trigger ci --- mailcatcher.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mailcatcher.gemspec b/mailcatcher.gemspec index 85e5e191..87fb0cd2 100644 --- a/mailcatcher.gemspec +++ b/mailcatcher.gemspec @@ -27,8 +27,8 @@ Gem::Specification.new do |s| "views/**/*", ] - Dir["lib/mail_catcher/web/assets.rb"] s.require_paths = ["lib"] - s.executables = ["mailcatcher", "catchmail"] - s.extra_rdoc_files = ["README.md", "LICENSE"] + s.executables = %w[mailcatcher catchmail] + s.extra_rdoc_files = %w[README.md LICENSE] s.required_ruby_version = ">= 2.6.0" From 4c07d57522a69410ca528b3249b1cb062e2119af Mon Sep 17 00:00:00 2001 From: Wanderfalke Date: Wed, 20 Apr 2022 14:06:13 +0200 Subject: [PATCH 07/11] Create main.yml --- .github/workflows/main.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..f94ce223 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + ruby-version: ['2.6', '2.7', '3.0', '3.1'] + + steps: + - uses: actions/checkout@v2 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + + - uses: actions/setup-node@v2 + + - uses: browser-actions/setup-chrome@latest + - uses: nanasess/setup-chromedriver@master + + - name: Run tests + run: bundle exec rake test + + - name: Upload test artifacts + uses: actions/upload-artifact@v2 + if: always() + with: + name: test-artifacts + path: tmp From b8197d19ba62d5d129b3d0e84cc01c0be8cfcd05 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 20 Apr 2022 14:07:18 +0200 Subject: [PATCH 08/11] remove workflow --- .github/workflows/main.yml | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index f94ce223..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: ubuntu-latest - - strategy: - matrix: - ruby-version: ['2.6', '2.7', '3.0', '3.1'] - - steps: - - uses: actions/checkout@v2 - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true - - - uses: actions/setup-node@v2 - - - uses: browser-actions/setup-chrome@latest - - uses: nanasess/setup-chromedriver@master - - - name: Run tests - run: bundle exec rake test - - - name: Upload test artifacts - uses: actions/upload-artifact@v2 - if: always() - with: - name: test-artifacts - path: tmp From a122c040b1795fa5143a1a5461fca990fcb14b7e Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 20 Apr 2022 14:16:39 +0200 Subject: [PATCH 09/11] try latest bundler --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f94ce223..bbbdaf55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} + bundler: 2.3.11 bundler-cache: true - uses: actions/setup-node@v2 From 13294a018850f65d22b0adc9ee01c132f04bcafc Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 20 Apr 2022 14:17:52 +0200 Subject: [PATCH 10/11] fix workflow syntax --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbbdaf55..131cc870 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} - bundler: 2.3.11 + bundler: '2.3.11' bundler-cache: true - uses: actions/setup-node@v2 From 544578c770f927f0c61f7870cf86f066b17c75d7 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 20 Apr 2022 14:30:02 +0200 Subject: [PATCH 11/11] fix workflow syntax --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 131cc870..6d927faa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} - bundler: '2.3.11' + bundler: '2.3.11' bundler-cache: true - uses: actions/setup-node@v2