test_bench-bootstrap 6.1.1 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/executables/bench-bootstrap +7 -0
- data/lib/test_bench_bootstrap/controls.rb +1 -0
- data/lib/test_bench_bootstrap/test_bench_bootstrap.rb +7 -0
- data/lib/test_bench_bootstrap.rb +4 -0
- data/upstream-lib/test_bench_bootstrap/import_constants/controls/namespace.rb +84 -0
- data/upstream-lib/test_bench_bootstrap/import_constants/controls.rb +1 -0
- data/upstream-lib/test_bench_bootstrap/import_constants/import_constants.rb +46 -0
- data/upstream-lib/test_bench_bootstrap/import_constants/macro.rb +10 -0
- data/upstream-lib/test_bench_bootstrap/import_constants.rb +2 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/controls/telemetry_sink.rb +7 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/controls.rb +3 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/controls/path.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/controls/random.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/controls/run.rb +12 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/controls/standard_input.rb +31 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/controls.rb +8 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/defaults.rb +15 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/executable.rb +61 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable/parse_arguments.rb +271 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/executable.rb +7 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/build.rb +41 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/comment_style.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/exception.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/fixture.rb +69 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/message.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/output.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/path.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/session.rb +21 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/status.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/text.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls/title.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/controls.rb +14 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/evaluate.rb +37 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture/fixture.rb +213 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/fixture.rb +7 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/comment_style.rb +63 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/comment_style.rb +23 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/event.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/aborted.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/commented.rb +23 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/context_finished.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/context_started.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/detailed.rb +23 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/failed.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/file_executed.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/file_not_found.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/file_queued.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/skipped.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/test_finished.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/events/test_started.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/random.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/session.rb +19 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/status.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/style.rb +41 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls/text.rb +31 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/controls.rb +26 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/detail_policy.rb +46 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/device/null.rb +21 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/device/substitute.rb +46 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/device.rb +75 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/get.rb +32 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/level.rb +53 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/output.rb +572 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/writer/style.rb +54 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/writer/substitute.rb +27 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output/writer.rb +119 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/output.rb +20 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/controls/seed.rb +25 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/controls/sequence.rb +70 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/controls.rb +2 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/defaults.rb +13 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/generator/substitute.rb +23 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/generator.rb +64 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/iterator.rb +54 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random/random.rb +27 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/random.rb +8 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/events.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/message.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/path.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/random.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/session.rb +16 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/status.rb +44 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/summary/file/info.rb +108 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/summary/file/totals.rb +38 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/summary/file.rb +44 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/summary/run.rb +53 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/summary.rb +45 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/telemetry.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls/time.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/controls.rb +20 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/run.rb +146 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/select_files/substitute.rb +45 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/select_files.rb +70 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/substitute.rb +42 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/summary/substitute.rb +19 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run/summary.rb +477 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/run.rb +10 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/backtrace/location.rb +48 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/backtrace.rb +83 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/comment_disposition.rb +17 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/event.rb +35 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/aborted.rb +51 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/commented.rb +62 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/context_finished.rb +112 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/context_started.rb +51 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/detailed.rb +62 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/failed.rb +41 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/file_executed.rb +101 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/file_not_found.rb +41 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/file_queued.rb +41 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/skipped.rb +51 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/test_finished.rb +92 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events/test_started.rb +51 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/events.rb +35 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/exception/message.rb +23 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/exception/raise.rb +52 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/exception.rb +81 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/message.rb +43 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/metadata.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/path/apex_directory.rb +76 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/path/file/create.rb +113 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/path/file.rb +42 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/path.rb +87 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/random.rb +9 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/result.rb +17 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/sequence.rb +13 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/status.rb +92 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/telemetry.rb +15 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/telemetry_sink.rb +37 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/text.rb +33 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls/title.rb +41 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/controls.rb +43 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/defaults.rb +17 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/events.rb +24 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/exception/format_backtrace/substitute.rb +34 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/exception/format_backtrace.rb +114 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/isolate/substitute.rb +45 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/isolate.rb +159 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/result.rb +44 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/session.rb +236 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/status.rb +60 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/substitute/sink.rb +99 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/substitute.rb +154 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session/trace.rb +53 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/session.rb +22 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/event/metadata.rb +72 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/event.rb +156 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/event_data.rb +113 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/handler.rb +83 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/path/file.rb +39 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/process_id.rb +25 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/random.rb +11 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/sink.rb +35 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls/time.rb +104 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/controls.rb +16 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/event.rb +130 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/event_data/serialization.rb +85 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/event_data.rb +15 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/sink/file.rb +39 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/sink/handler/event_registry.rb +44 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/sink/handler.rb +128 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/sink.rb +13 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/substitute/sink.rb +71 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/substitute.rb +43 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry/telemetry.rb +92 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/telemetry.rb +18 -0
- data/upstream-lib/test_bench_bootstrap/test_bench/test_bench.rb +72 -0
- data/upstream-lib/test_bench_bootstrap/test_bench.rb +4 -0
- metadata +353 -16
- data/lib/test_bench/bootstrap.rb +0 -328
@@ -0,0 +1,130 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
module Event
|
5
|
+
def self.define(*attributes, &blk)
|
6
|
+
Struct.new(*attributes, :metadata) do
|
7
|
+
include Event
|
8
|
+
|
9
|
+
if not blk.nil?
|
10
|
+
instance_exec(&blk)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.included(cls)
|
16
|
+
cls.class_exec do
|
17
|
+
extend EventType
|
18
|
+
extend EventName
|
19
|
+
|
20
|
+
extend Build
|
21
|
+
|
22
|
+
extend CaseEquality
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def event_type
|
27
|
+
self.class.event_type
|
28
|
+
end
|
29
|
+
|
30
|
+
def event_name
|
31
|
+
self.class.event_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def data
|
35
|
+
values[0...-1]
|
36
|
+
end
|
37
|
+
|
38
|
+
module EventType
|
39
|
+
def event_type
|
40
|
+
@event_type ||= event_type!
|
41
|
+
end
|
42
|
+
|
43
|
+
def event_type!
|
44
|
+
*, inner_namespace = self.name.split('::')
|
45
|
+
|
46
|
+
inner_namespace.to_sym
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module EventName
|
51
|
+
def event_name
|
52
|
+
EventName.get(event_type)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get(event_type)
|
56
|
+
pascal_cased = event_type.to_s
|
57
|
+
|
58
|
+
underscore_cased = pascal_cased.gsub(%r{(?:\A|[a-z])[A-Z]+}) do |match_text|
|
59
|
+
if ('a'..'z').include?(match_text[0])
|
60
|
+
match_text.insert(1, '_')
|
61
|
+
end
|
62
|
+
match_text.downcase!
|
63
|
+
match_text
|
64
|
+
end
|
65
|
+
|
66
|
+
underscore_cased.to_sym
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module Export
|
71
|
+
def self.call(event)
|
72
|
+
event_data = EventData.new
|
73
|
+
event_data.type = event.event_type
|
74
|
+
event_data.data = event.data
|
75
|
+
event_data.process_id = event.metadata.process_id
|
76
|
+
event_data.time = event.metadata.time
|
77
|
+
event_data
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
module Build
|
82
|
+
def build(*attributes, process_id: nil, time: nil)
|
83
|
+
time ||= ::Time.now
|
84
|
+
process_id ||= ::Process.pid
|
85
|
+
|
86
|
+
metadata = Metadata.new(process_id, time)
|
87
|
+
|
88
|
+
instance = new(*attributes)
|
89
|
+
instance.metadata = metadata
|
90
|
+
instance
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module CaseEquality
|
95
|
+
def ===(object)
|
96
|
+
case object
|
97
|
+
in EventData => event_data
|
98
|
+
type = event_data.type
|
99
|
+
|
100
|
+
type == self.event_type
|
101
|
+
|
102
|
+
else
|
103
|
+
super(object)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module Import
|
109
|
+
Error = Class.new(RuntimeError)
|
110
|
+
|
111
|
+
def self.call(event_data, event_class)
|
112
|
+
if event_class.event_type != event_data.type
|
113
|
+
raise Error, "Event class #{event_class} doesn't match EventData type #{event_data.type.inspect}"
|
114
|
+
end
|
115
|
+
|
116
|
+
process_id = event_data.process_id
|
117
|
+
time = event_data.time
|
118
|
+
data = event_data.data
|
119
|
+
|
120
|
+
metadata = Metadata.new(process_id, time)
|
121
|
+
|
122
|
+
event_class.new(*data, metadata)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
Metadata = Struct.new(:process_id, :time)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
class EventData
|
5
|
+
module Serialization
|
6
|
+
def self.dump(event_data)
|
7
|
+
data = event_data.data.map do |value|
|
8
|
+
case value
|
9
|
+
in Time => time
|
10
|
+
timestamp(time)
|
11
|
+
else
|
12
|
+
value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
type = event_data.type
|
17
|
+
process_id = event_data.process_id
|
18
|
+
|
19
|
+
time = event_data.time
|
20
|
+
if not time.nil?
|
21
|
+
timestamp = timestamp(time)
|
22
|
+
end
|
23
|
+
|
24
|
+
json_text = JSON.generate([type, process_id, timestamp, data])
|
25
|
+
json_text << "\n"
|
26
|
+
json_text
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.load(text)
|
30
|
+
type, process_id, timestamp, data = JSON.parse(text)
|
31
|
+
|
32
|
+
type = type.to_sym
|
33
|
+
|
34
|
+
if not timestamp.nil?
|
35
|
+
time = time(timestamp)
|
36
|
+
end
|
37
|
+
|
38
|
+
event_data = EventData.new
|
39
|
+
event_data.type = type
|
40
|
+
event_data.process_id = process_id
|
41
|
+
event_data.time = time
|
42
|
+
event_data.data = data
|
43
|
+
|
44
|
+
event_data
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.timestamp(time)
|
48
|
+
time.strftime('%Y-%m-%dT%H:%M:%S.%NZ')
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.time(timestamp)
|
52
|
+
match_data = time_pattern.match(timestamp)
|
53
|
+
|
54
|
+
year = match_data['year'].to_i
|
55
|
+
month = match_data['month'].to_i
|
56
|
+
day = match_data['day'].to_i
|
57
|
+
hour = match_data['hour'].to_i
|
58
|
+
minute = match_data['minute'].to_i
|
59
|
+
second = match_data['second'].to_i
|
60
|
+
|
61
|
+
nanosecond = match_data['nanosecond'].to_i
|
62
|
+
usec = Rational(nanosecond, 1_000)
|
63
|
+
|
64
|
+
Time.utc(year, month, day, hour, minute, second, usec)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.time_pattern
|
68
|
+
@time_pattern ||=
|
69
|
+
begin
|
70
|
+
year = %r{(?<year>[[:digit:]]{4})}
|
71
|
+
month = %r{(?<month>[[:digit:]]{2})}
|
72
|
+
day = %r{(?<day>[[:digit:]]{2})}
|
73
|
+
hour = %r{(?<hour>[[:digit:]]{2})}
|
74
|
+
minute = %r{(?<minute>[[:digit:]]{2})}
|
75
|
+
second = %r{(?<second>[[:digit:]]{2})}
|
76
|
+
nanosecond = %r{(?<nanosecond>[[:digit:]]{9})}
|
77
|
+
|
78
|
+
%r{\A#{year}-#{month}-#{day}T#{hour}:#{minute}:#{second}\.#{nanosecond}Z\z}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
EventData = Struct.new(:type, :process_id, :time, :data) do
|
5
|
+
def self.load(text)
|
6
|
+
EventData::Serialization.load(text)
|
7
|
+
end
|
8
|
+
|
9
|
+
def dump
|
10
|
+
EventData::Serialization.dump(self)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
module Sink
|
5
|
+
class File
|
6
|
+
include Sink
|
7
|
+
|
8
|
+
attr_reader :file
|
9
|
+
|
10
|
+
def initialize(file)
|
11
|
+
@file = file
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.build(file_path)
|
15
|
+
file = ::File.open(file_path, 'w')
|
16
|
+
|
17
|
+
new(file)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.open(file_path, &block)
|
21
|
+
::File.open(file_path, 'w') do |file|
|
22
|
+
instance = new(file)
|
23
|
+
|
24
|
+
block.(instance, file)
|
25
|
+
|
26
|
+
return instance
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def receive(event_data)
|
31
|
+
text = event_data.dump
|
32
|
+
|
33
|
+
file.write(text)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
module Sink
|
5
|
+
module Handler
|
6
|
+
class EventRegistry
|
7
|
+
Error = Class.new(RuntimeError)
|
8
|
+
|
9
|
+
def event_classes
|
10
|
+
@event_classes ||= {}
|
11
|
+
end
|
12
|
+
attr_writer :event_classes
|
13
|
+
|
14
|
+
def event_types
|
15
|
+
event_classes.keys
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(event_type)
|
19
|
+
event_classes.fetch(event_type) do
|
20
|
+
raise Error, "#{event_type} isn't registered"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def register(event_class)
|
25
|
+
if registered?(event_class)
|
26
|
+
raise Error, "#{event_class} is already registered"
|
27
|
+
end
|
28
|
+
|
29
|
+
event_type = event_class.event_type
|
30
|
+
|
31
|
+
event_classes[event_type] = event_class
|
32
|
+
end
|
33
|
+
|
34
|
+
def registered?(event_class)
|
35
|
+
event_type = event_class.event_type
|
36
|
+
|
37
|
+
event_classes.key?(event_type)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
module Sink
|
5
|
+
module Handler
|
6
|
+
def self.included(cls)
|
7
|
+
cls.class_exec do
|
8
|
+
include Sink
|
9
|
+
include Receive
|
10
|
+
|
11
|
+
extend HandlerMethod
|
12
|
+
extend HandleMacro
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Receive
|
17
|
+
def receive(event_data)
|
18
|
+
handle(event_data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle(event_or_event_data)
|
23
|
+
handles = handle?(event_or_event_data)
|
24
|
+
|
25
|
+
if handles
|
26
|
+
if event_or_event_data.is_a?(Event)
|
27
|
+
event = event_or_event_data
|
28
|
+
else
|
29
|
+
event_data = event_or_event_data
|
30
|
+
event_type = event_data.type
|
31
|
+
event_class = self.class.event_registry.get(event_type)
|
32
|
+
|
33
|
+
event = Event::Import.(event_data, event_class)
|
34
|
+
end
|
35
|
+
|
36
|
+
handler_method = handler_method(event)
|
37
|
+
|
38
|
+
if method(handler_method).parameters.any?
|
39
|
+
__send__(handler_method, event)
|
40
|
+
else
|
41
|
+
__send__(handler_method)
|
42
|
+
end
|
43
|
+
|
44
|
+
event
|
45
|
+
elsif respond_to?(:handle_event_data)
|
46
|
+
if event_or_event_data.is_a?(Event)
|
47
|
+
event_data = Event::Export.(event_or_event_data)
|
48
|
+
else
|
49
|
+
event_data = event_or_event_data
|
50
|
+
end
|
51
|
+
|
52
|
+
handle_event_data(event_data)
|
53
|
+
|
54
|
+
event_data
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def handle?(...)
|
61
|
+
handler_method = handler_method(...)
|
62
|
+
|
63
|
+
not handler_method.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
def handler_method(event_or_event_data)
|
67
|
+
handler_method = self.class.handler_method(event_or_event_data)
|
68
|
+
|
69
|
+
if respond_to?(handler_method)
|
70
|
+
handler_method
|
71
|
+
else
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module HandleMacro
|
77
|
+
def handle_macro(event_class, &block)
|
78
|
+
event_registry.register(event_class)
|
79
|
+
|
80
|
+
event_type = event_class.event_type
|
81
|
+
|
82
|
+
handler_method = HandlerMethod.get(event_type)
|
83
|
+
|
84
|
+
define_method(handler_method, &block)
|
85
|
+
end
|
86
|
+
alias :handle :handle_macro
|
87
|
+
|
88
|
+
def event_registry
|
89
|
+
@event_registry ||= EventRegistry.new
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
module HandlerMethod
|
94
|
+
def handler_method(event_or_event_data)
|
95
|
+
if event_or_event_data.is_a?(Event)
|
96
|
+
event = event_or_event_data
|
97
|
+
event_type = event.event_type
|
98
|
+
else
|
99
|
+
event_data = event_or_event_data
|
100
|
+
event_type = event_data.type
|
101
|
+
end
|
102
|
+
|
103
|
+
HandlerMethod.get(event_type)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.get(event_type)
|
107
|
+
handler_methods[event_type]
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.handler_methods
|
111
|
+
@handler_methods ||= Hash.new do |handler_methods, event_type|
|
112
|
+
handler_method = get!(event_type)
|
113
|
+
|
114
|
+
handler_methods[event_type] = handler_method
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.get!(event_type)
|
119
|
+
event_name = Event::EventName.get(event_type)
|
120
|
+
|
121
|
+
:"handle_#{event_name}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
module Substitute
|
5
|
+
class Sink
|
6
|
+
MatchError = Class.new(RuntimeError)
|
7
|
+
|
8
|
+
include Telemetry::Sink
|
9
|
+
|
10
|
+
def received_events
|
11
|
+
@received_events ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
def receive(event_data)
|
15
|
+
received_events << event_data
|
16
|
+
end
|
17
|
+
|
18
|
+
def received?(event_data)
|
19
|
+
received_events.include?(event_data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def one_event?(...)
|
23
|
+
!one_event(...).nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def one_event(...)
|
27
|
+
events = events(...)
|
28
|
+
|
29
|
+
if events.count > 1
|
30
|
+
event_type = events.first.event_type
|
31
|
+
raise MatchError, "More than one event matches (Type: #{event_type.inspect}, Matching Events: #{events.count})"
|
32
|
+
end
|
33
|
+
|
34
|
+
events.first
|
35
|
+
end
|
36
|
+
|
37
|
+
def any_event?(...)
|
38
|
+
events(...).any?
|
39
|
+
end
|
40
|
+
alias :event? :any_event?
|
41
|
+
|
42
|
+
def events(event_class, **attributes)
|
43
|
+
event_type = event_class.event_type
|
44
|
+
|
45
|
+
events = []
|
46
|
+
|
47
|
+
received_events.each do |event_data|
|
48
|
+
event_types_correspond = event_data.type == event_type
|
49
|
+
|
50
|
+
if event_types_correspond
|
51
|
+
event = Event::Import.(event_data, event_class)
|
52
|
+
|
53
|
+
attributes_correspond = attributes.all? do |attribute, compare_value|
|
54
|
+
value = event.public_send(attribute)
|
55
|
+
|
56
|
+
value == compare_value
|
57
|
+
end
|
58
|
+
|
59
|
+
if attributes_correspond
|
60
|
+
events << event
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
events
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
module Substitute
|
5
|
+
def self.build
|
6
|
+
Telemetry.build
|
7
|
+
end
|
8
|
+
|
9
|
+
class Telemetry < Telemetry
|
10
|
+
attr_accessor :process_id
|
11
|
+
attr_accessor :current_time
|
12
|
+
|
13
|
+
def sink
|
14
|
+
@sink ||= Substitute::Sink.new
|
15
|
+
end
|
16
|
+
attr_writer :sink
|
17
|
+
|
18
|
+
def self.build
|
19
|
+
instance = new
|
20
|
+
instance.register(instance.sink)
|
21
|
+
instance
|
22
|
+
end
|
23
|
+
|
24
|
+
def one_event?(...) = sink.one_event?(...)
|
25
|
+
def one_event(...) = sink.one_event(...)
|
26
|
+
def any_event?(...) = sink.any_event?(...)
|
27
|
+
alias :event? :any_event?
|
28
|
+
def events(...) = sink.events(...)
|
29
|
+
|
30
|
+
def recorded?(event_or_event_data)
|
31
|
+
case event_or_event_data
|
32
|
+
in Event => event
|
33
|
+
event_data = Event::Export.(event)
|
34
|
+
in EventData => event_data
|
35
|
+
end
|
36
|
+
|
37
|
+
sink.received?(event_data)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module TestBenchBootstrap
|
2
|
+
module TestBench
|
3
|
+
class Telemetry
|
4
|
+
RegistrationError = Class.new(RuntimeError)
|
5
|
+
GetError = Class.new(RuntimeError)
|
6
|
+
|
7
|
+
def sinks
|
8
|
+
@sinks ||= []
|
9
|
+
end
|
10
|
+
attr_writer :sinks
|
11
|
+
|
12
|
+
def self.build(*sinks)
|
13
|
+
instance = new
|
14
|
+
|
15
|
+
sinks.each do |sink|
|
16
|
+
instance.register(sink)
|
17
|
+
end
|
18
|
+
|
19
|
+
instance
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configure(receiver, *sinks, attr_name: nil)
|
23
|
+
attr_name ||= :telemetry
|
24
|
+
|
25
|
+
instance = build(*sinks)
|
26
|
+
receiver.public_send(:"#{attr_name}=", instance)
|
27
|
+
end
|
28
|
+
|
29
|
+
def record(event)
|
30
|
+
if event.is_a?(Event)
|
31
|
+
event.metadata ||= Event::Metadata.new
|
32
|
+
|
33
|
+
event_data = Event::Export.(event)
|
34
|
+
else
|
35
|
+
event_data = event
|
36
|
+
end
|
37
|
+
|
38
|
+
sinks.each do |sink|
|
39
|
+
sink.receive(event_data)
|
40
|
+
end
|
41
|
+
|
42
|
+
event_data
|
43
|
+
end
|
44
|
+
|
45
|
+
def register(sink)
|
46
|
+
if registered?(sink)
|
47
|
+
raise RegistrationError, "Already registered #{sink.inspect}"
|
48
|
+
end
|
49
|
+
|
50
|
+
sinks.push(sink)
|
51
|
+
end
|
52
|
+
|
53
|
+
def unregister(sink)
|
54
|
+
deleted_sink = sinks.delete(sink)
|
55
|
+
|
56
|
+
if deleted_sink.nil?
|
57
|
+
raise RegistrationError, "Not registered #{sink.inspect}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def registered?(sink_or_sink_class)
|
62
|
+
if sink_or_sink_class.is_a?(Sink)
|
63
|
+
sink = sink_or_sink_class
|
64
|
+
|
65
|
+
sinks.include?(sink)
|
66
|
+
else
|
67
|
+
sink_class = sink_or_sink_class
|
68
|
+
|
69
|
+
sink = get_sink(sink_class)
|
70
|
+
|
71
|
+
!sink.nil?
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_sink(sink_class)
|
76
|
+
sink, *other_sinks = get_sinks(sink_class)
|
77
|
+
|
78
|
+
if other_sinks.any?
|
79
|
+
raise GetError, "Multiple sinks match: #{sink_class.inspect}"
|
80
|
+
end
|
81
|
+
|
82
|
+
sink
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_sinks(sink_class)
|
86
|
+
sinks.select do |sink|
|
87
|
+
sink.instance_of?(sink_class)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require 'test_bench_bootstrap/test_bench/random'
|
4
|
+
|
5
|
+
require 'test_bench_bootstrap/test_bench/telemetry/event_data'
|
6
|
+
require 'test_bench_bootstrap/test_bench/telemetry/event_data/serialization'
|
7
|
+
|
8
|
+
require 'test_bench_bootstrap/test_bench/telemetry/event'
|
9
|
+
|
10
|
+
require 'test_bench_bootstrap/test_bench/telemetry/sink'
|
11
|
+
require 'test_bench_bootstrap/test_bench/telemetry/sink/file'
|
12
|
+
require 'test_bench_bootstrap/test_bench/telemetry/sink/handler/event_registry'
|
13
|
+
require 'test_bench_bootstrap/test_bench/telemetry/sink/handler'
|
14
|
+
|
15
|
+
require 'test_bench_bootstrap/test_bench/telemetry/telemetry'
|
16
|
+
|
17
|
+
require 'test_bench_bootstrap/test_bench/telemetry/substitute/sink'
|
18
|
+
require 'test_bench_bootstrap/test_bench/telemetry/substitute'
|