Skip to content

Commit 312d1df

Browse files
committed
skip forking tests on windows and java platforms
1 parent dedabe7 commit 312d1df

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

metrics_sdk/test/integration/periodic_metric_reader_test.rb

+29-27
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,44 @@
8383
_(periodic_metric_reader.instance_variable_get(:@thread).alive?).must_equal false
8484
end
8585

86-
it 'is restarted after forking' do
87-
OpenTelemetry::SDK.configure
86+
unless Gem.win_platform? || Gem.java_platform? # skip as forking is not available on these platforms
87+
it 'is restarted after forking' do
88+
OpenTelemetry::SDK.configure
8889

89-
metric_exporter = OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter.new
90-
periodic_metric_reader = OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.new(export_interval_millis: 5000, export_timeout_millis: 5000, exporter: metric_exporter)
90+
metric_exporter = OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter.new
91+
periodic_metric_reader = OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.new(export_interval_millis: 5000, export_timeout_millis: 5000, exporter: metric_exporter)
9192

92-
OpenTelemetry.meter_provider.add_metric_reader(periodic_metric_reader)
93+
OpenTelemetry.meter_provider.add_metric_reader(periodic_metric_reader)
9394

94-
read, write = IO.pipe
95+
read, write = IO.pipe
9596

96-
pid = fork do
97-
meter = OpenTelemetry.meter_provider.meter('test')
98-
counter = meter.create_counter('counter', unit: 'smidgen', description: 'a small amount of something')
97+
pid = fork do
98+
meter = OpenTelemetry.meter_provider.meter('test')
99+
counter = meter.create_counter('counter', unit: 'smidgen', description: 'a small amount of something')
99100

100-
counter.add(1)
101-
counter.add(2, attributes: { 'a' => 'b' })
102-
counter.add(2, attributes: { 'a' => 'b' })
103-
counter.add(3, attributes: { 'b' => 'c' })
104-
counter.add(4, attributes: { 'd' => 'e' })
101+
counter.add(1)
102+
counter.add(2, attributes: { 'a' => 'b' })
103+
counter.add(2, attributes: { 'a' => 'b' })
104+
counter.add(3, attributes: { 'b' => 'c' })
105+
counter.add(4, attributes: { 'd' => 'e' })
105106

106-
sleep(8)
107-
snapshot = metric_exporter.metric_snapshots
107+
sleep(8)
108+
snapshot = metric_exporter.metric_snapshots
108109

109-
json = snapshot.map { |reading| { name: reading.name } }.to_json
110-
write.puts json
111-
end
110+
json = snapshot.map { |reading| { name: reading.name } }.to_json
111+
write.puts json
112+
end
112113

113-
Timeout.timeout(10) do
114-
Process.waitpid(pid)
115-
end
114+
Timeout.timeout(10) do
115+
Process.waitpid(pid)
116+
end
116117

117-
periodic_metric_reader.shutdown
118-
snapshot = JSON.parse(read.gets.chomp)
119-
_(snapshot.size).must_equal(1)
120-
_(snapshot[0]).must_equal('name' => 'counter')
121-
_(periodic_metric_reader.instance_variable_get(:@thread).alive?).must_equal false
118+
periodic_metric_reader.shutdown
119+
snapshot = JSON.parse(read.gets.chomp)
120+
_(snapshot.size).must_equal(1)
121+
_(snapshot[0]).must_equal('name' => 'counter')
122+
_(periodic_metric_reader.instance_variable_get(:@thread).alive?).must_equal false
123+
end
122124
end
123125
end
124126
end

metrics_sdk/test/opentelemetry/sdk/metrics/fork_hooks_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7+
return if Gem.win_platform? || Gem.java_platform? # forking is not available on these platforms
8+
79
require 'test_helper'
810
require 'json'
911

0 commit comments

Comments
 (0)