File tree Expand file tree Collapse file tree 5 files changed +37
-2
lines changed
Expand file tree Collapse file tree 5 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ def sample!
9494 #
9595 # @yields {|process_id, monitor| ...} each process ID and monitor that is leaking or exceeds the memory limit.
9696 def check! ( &block )
97+ return to_enum ( __method__ ) unless block_given?
98+
9799 self . sample!
98100
99101 leaking = [ ]
Original file line number Diff line number Diff line change 44# Copyright, 2025, by Samuel Williams.
55
66require "console"
7+ require_relative "system"
78
89module Memory
910 module Leak
Original file line number Diff line number Diff line change @@ -15,8 +15,6 @@ def self.total_memory_size
1515 return total . to_i * 1024
1616 end
1717 end
18-
19- return nil
2018 end
2119 elsif RUBY_PLATFORM =~ /darwin/
2220 def self . total_memory_size
Original file line number Diff line number Diff line change 1313
1414 let ( :cluster ) { subject . new }
1515
16+ with "#as_json" do
17+ it "generates a JSON representation" do
18+ expect ( cluster . as_json ) . to have_keys (
19+ processes : be_a ( Hash ) ,
20+ total_size : be_nil ,
21+ total_size_limit : be_nil ,
22+ )
23+ end
24+
25+ it "generates a JSON string" do
26+ expect ( JSON . dump ( cluster ) ) . to be == cluster . to_json
27+ end
28+ end
29+
1630 with "a leaking child process" do
1731 before do
1832 @children = 3 . times . map do
6579 # 100 MiB limit:
6680 cluster . total_size_limit = 1024 *1024 *100
6781
82+ expect ( cluster . check! . to_a ) . to be ( :empty? )
83+
6884 big_child = children . values . first
6985 big_monitor = cluster . processes [ big_child . process_id ]
7086 small_child = children . values . last
Original file line number Diff line number Diff line change 99describe Memory ::Leak ::Monitor do
1010 let ( :monitor ) { subject . new }
1111
12+ with "#as_json" do
13+ it "generates a JSON representation" do
14+ expect ( monitor . as_json ) . to have_keys (
15+ process_id : be_a ( Integer ) ,
16+ current_size : be_nil ,
17+ maximum_size : be_nil ,
18+ maximum_size_limit : be_nil ,
19+ threshold_size : be_a ( Integer ) ,
20+ increase_count : be == 0 ,
21+ increase_limit : be_a ( Integer )
22+ )
23+ end
24+
25+ it "generates a JSON string" do
26+ expect ( JSON . dump ( monitor ) ) . to be == monitor . to_json
27+ end
28+ end
29+
1230 with "#sample!" do
1331 it "can capture samples" do
1432 3 . times do
You can’t perform that action at this time.
0 commit comments