Sha256: 80dcfdfc39497b0a7943bb7f343c733e794c1b5e5b882c97990741fc7f70d323

Contents?: true

Size: 1.91 KB

Versions: 210

Compression:

Stored size: 1.91 KB

Contents

describe Appsignal::GarbageCollectionProfiler do
  let(:internal_profiler) { FakeGCProfiler.new }
  let(:profiler) { described_class.new }

  before do
    allow_any_instance_of(described_class)
      .to receive(:internal_profiler)
      .and_return(internal_profiler)
  end

  context "on initialization" do
    it "has a total time of 0" do
      expect(profiler.total_time).to eq(0)
    end
  end

  context "when the GC has run" do
    before { internal_profiler.total_time = 0.12345 }

    it "fetches the total time from Ruby's GC::Profiler" do
      expect(profiler.total_time).to eq(123)
    end

    it "clears Ruby's GC::Profiler afterward" do
      expect(internal_profiler).to receive(:clear)
      profiler.total_time
    end
  end

  context "when the total GC time becomes too high" do
    it "resets the total time" do
      internal_profiler.total_time = 2_147_483_647
      expect(profiler.total_time).to eq(0)
    end
  end

  context "when the GC has run multiple times" do
    it "adds all times from Ruby's GC::Profiler together" do
      2.times do
        internal_profiler.total_time = 0.12345
        profiler.total_time
      end

      expect(profiler.total_time).to eq(246)
    end
  end

  context "when in multiple threads and with a slow GC::Profiler" do
    it "does not count garbage collection times twice" do
      threads = []
      results = []
      internal_profiler.clear_delay = 0.001
      internal_profiler.total_time = 0.12345

      2.times do
        threads << Thread.new do
          profiler = Appsignal::GarbageCollectionProfiler.new
          results << profiler.total_time
        end
      end

      threads.each(&:join)
      expect(results).to eq([123, 0])
    end
  end
end

describe Appsignal::NilGarbageCollectionProfiler do
  let(:profiler) { described_class.new }

  describe "#total_time" do
    it "has a total time of 0" do
      expect(profiler.total_time).to eq(0)
    end
  end
end

Version data entries

210 entries across 210 versions & 1 rubygems

Version Path
appsignal-3.1.3-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.1.3 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.1.2-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.1.2 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.1.1-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.1.1 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.1.0-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.1.0 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.27-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.27 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.26-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.26 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.25-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.25 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.24-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.24 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.23-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.23 spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.22-java spec/lib/appsignal/garbage_collection_profiler_spec.rb
appsignal-3.0.22 spec/lib/appsignal/garbage_collection_profiler_spec.rb