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
87
87
expect ( input . read ) . to be == "true"
88
88
end
89
89
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
+
90
111
with "#sleep" do
91
112
it "can sleep for a short time" do
92
113
container . spawn do
Original file line number Diff line number Diff line change @@ -41,6 +41,17 @@ def initialize(io)
41
41
@name = nil
42
42
end
43
43
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
+
44
55
# Set the process title to the specified value.
45
56
# @parameter value [String] The name of the process.
46
57
def name = value
Original file line number Diff line number Diff line change @@ -59,6 +59,18 @@ def initialize(io)
59
59
super
60
60
end
61
61
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
+
62
74
# Set the name of the thread.
63
75
# @parameter value [String] The name to set.
64
76
def name = value
You can’t perform that action at this time.
0 commit comments