diff --git a/lib/gitlab/puma_logging/json_formatter.rb b/lib/gitlab/puma_logging/json_formatter.rb index 9eeb980fc534d2d8572f52fc46c7a9f0acdca223..6d97b6615aa5c9659496a05da05ee07208f9b809 100644 --- a/lib/gitlab/puma_logging/json_formatter.rb +++ b/lib/gitlab/puma_logging/json_formatter.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'json' +require 'time' module Gitlab module PumaLogging diff --git a/lib/gitlab/runtime.rb b/lib/gitlab/runtime.rb index 7e9fb82fb8b536328bc24a4fe3434819b49b8eee..f74f1489405651c01627e80dbb645be2656fe88a 100644 --- a/lib/gitlab/runtime.rb +++ b/lib/gitlab/runtime.rb @@ -38,7 +38,7 @@ def safe_identify end def puma? - !!defined?(::Puma) + !!defined?(::Puma::Server) end def sidekiq? diff --git a/spec/lib/gitlab/runtime_spec.rb b/spec/lib/gitlab/runtime_spec.rb index 181a911c66713502229e2d487e2ab356e3975c55..fa0fad6552068f05ff5d51194f47204f738f9789 100644 --- a/spec/lib/gitlab/runtime_spec.rb +++ b/spec/lib/gitlab/runtime_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Runtime do +RSpec.describe Gitlab::Runtime, feature_category: :application_performance do shared_examples "valid runtime" do |runtime, max_threads| it "identifies itself" do expect(subject.identify).to eq(runtime) @@ -39,9 +39,21 @@ end end + context 'with Puma' do + before do + stub_const('::Puma::Server', double) + end + + describe '.puma?' do + it 'returns true' do + expect(subject.puma?).to be true + end + end + end + context "on multiple matches" do before do - stub_const('::Puma', double) + stub_const('::Puma::Server', double) stub_const('::Rails::Console', double) end @@ -64,6 +76,7 @@ before do stub_const('::Puma', puma_type) + allow(described_class).to receive(:puma?).and_return(true) end it_behaves_like "valid runtime", :puma, 1 + Gitlab::ActionCable::Config.worker_pool_size @@ -75,6 +88,7 @@ before do stub_const('::Puma', puma_type) + allow(described_class).to receive(:puma?).and_return(true) allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2, workers: max_workers) end