File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,27 @@ module Container
8787 expect ( input . read ) . to be == "true"
8888 end
8989
90+ with "instance" do
91+ it "can generate JSON representation" do
92+ IO . pipe do |input , output |
93+ container . spawn do |instance |
94+ output . write ( instance . to_json )
95+ end
96+
97+ container . wait
98+
99+ expect ( container . statistics ) . to have_attributes ( failures : be == 0 )
100+
101+ output . close
102+ instance = JSON . parse ( input . read , symbolize_names : true )
103+ expect ( instance ) . to have_keys (
104+ process_id : be_a ( Integer ) ,
105+ name : be_a ( String ) ,
106+ )
107+ end
108+ end
109+ end
110+
90111 with "#sleep" do
91112 it "can sleep for a short time" do
92113 container . spawn do
Original file line number Diff line number Diff line change @@ -41,6 +41,17 @@ def initialize(io)
4141 @name = nil
4242 end
4343
44+ def as_json ( ...)
45+ {
46+ process_id : ::Process . pid ,
47+ name : @name ,
48+ }
49+ end
50+
51+ def to_json ( ...)
52+ as_json . to_json ( ...)
53+ end
54+
4455 # Set the process title to the specified value.
4556 # @parameter value [String] The name of the process.
4657 def name = value
Original file line number Diff line number Diff line change @@ -59,6 +59,18 @@ def initialize(io)
5959 super
6060 end
6161
62+ def as_json ( ...)
63+ {
64+ process_id : ::Process . pid ,
65+ thread_id : @thread . object_id ,
66+ name : @thread . name ,
67+ }
68+ end
69+
70+ def to_json ( ...)
71+ as_json . to_json ( ...)
72+ end
73+
6274 # Set the name of the thread.
6375 # @parameter value [String] The name to set.
6476 def name = value
You can’t perform that action at this time.
0 commit comments