Skip to content

Commit

Permalink
skip forking tests on windows and java platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisholmes committed Mar 7, 2025
1 parent dedabe7 commit 312d1df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
56 changes: 29 additions & 27 deletions metrics_sdk/test/integration/periodic_metric_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,44 @@
_(periodic_metric_reader.instance_variable_get(:@thread).alive?).must_equal false
end

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

metric_exporter = OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter.new
periodic_metric_reader = OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.new(export_interval_millis: 5000, export_timeout_millis: 5000, exporter: metric_exporter)
metric_exporter = OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter.new
periodic_metric_reader = OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader.new(export_interval_millis: 5000, export_timeout_millis: 5000, exporter: metric_exporter)

OpenTelemetry.meter_provider.add_metric_reader(periodic_metric_reader)
OpenTelemetry.meter_provider.add_metric_reader(periodic_metric_reader)

read, write = IO.pipe
read, write = IO.pipe

pid = fork do
meter = OpenTelemetry.meter_provider.meter('test')
counter = meter.create_counter('counter', unit: 'smidgen', description: 'a small amount of something')
pid = fork do
meter = OpenTelemetry.meter_provider.meter('test')
counter = meter.create_counter('counter', unit: 'smidgen', description: 'a small amount of something')

counter.add(1)
counter.add(2, attributes: { 'a' => 'b' })
counter.add(2, attributes: { 'a' => 'b' })
counter.add(3, attributes: { 'b' => 'c' })
counter.add(4, attributes: { 'd' => 'e' })
counter.add(1)
counter.add(2, attributes: { 'a' => 'b' })
counter.add(2, attributes: { 'a' => 'b' })
counter.add(3, attributes: { 'b' => 'c' })
counter.add(4, attributes: { 'd' => 'e' })

sleep(8)
snapshot = metric_exporter.metric_snapshots
sleep(8)
snapshot = metric_exporter.metric_snapshots

json = snapshot.map { |reading| { name: reading.name } }.to_json
write.puts json
end
json = snapshot.map { |reading| { name: reading.name } }.to_json
write.puts json
end

Timeout.timeout(10) do
Process.waitpid(pid)
end
Timeout.timeout(10) do
Process.waitpid(pid)
end

periodic_metric_reader.shutdown
snapshot = JSON.parse(read.gets.chomp)
_(snapshot.size).must_equal(1)
_(snapshot[0]).must_equal('name' => 'counter')
_(periodic_metric_reader.instance_variable_get(:@thread).alive?).must_equal false
periodic_metric_reader.shutdown
snapshot = JSON.parse(read.gets.chomp)
_(snapshot.size).must_equal(1)
_(snapshot[0]).must_equal('name' => 'counter')
_(periodic_metric_reader.instance_variable_get(:@thread).alive?).must_equal false
end
end
end
end
2 changes: 2 additions & 0 deletions metrics_sdk/test/opentelemetry/sdk/metrics/fork_hooks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# SPDX-License-Identifier: Apache-2.0

return if Gem.win_platform? || Gem.java_platform? # forking is not available on these platforms

require 'test_helper'
require 'json'

Expand Down

0 comments on commit 312d1df

Please sign in to comment.