|
4 | 4 | RSpec.describe 'DI initializer' do
|
5 | 5 | di_test
|
6 | 6 |
|
7 |
| - context 'when loaded initially into a clean process' do |
8 |
| - it 'loads only DI code tracker' do |
9 |
| - script = <<-SCRIPT |
10 |
| - if defined?(Datadog) && Datadog.constants != %i(VERSION) |
11 |
| - raise "Datadog code loaded too early" |
12 |
| - end |
| 7 | + BOOTSTRAP_SCRIPT = <<-SCRIPT |
| 8 | + if defined?(Datadog) && Datadog.constants != %i(VERSION) |
| 9 | + raise "Datadog code loaded too early" |
| 10 | + end |
13 | 11 |
|
14 |
| - require 'datadog/di/init' |
| 12 | + require 'datadog/di/init' |
15 | 13 |
|
16 |
| - if Datadog.constants.sort != %i(DI VERSION) |
17 |
| - raise "Too many datadog components loaded: \#{Datadog.constants}" |
18 |
| - end |
| 14 | + if Datadog.constants.sort != %i(DI VERSION) |
| 15 | + raise "Too many datadog components loaded: \#{Datadog.constants}" |
| 16 | + end |
19 | 17 |
|
20 |
| - unless Datadog::DI.code_tracker |
21 |
| - raise "Code tracker not instantiated" |
22 |
| - end |
| 18 | + unless Datadog::DI.code_tracker |
| 19 | + raise "Code tracker not instantiated" |
| 20 | + end |
23 | 21 |
|
24 |
| - unless Datadog::DI.code_tracker.send(:registry).empty? |
25 |
| - raise "Code tracker registry is not empty" |
26 |
| - end |
| 22 | + unless Datadog::DI.code_tracker.send(:registry).empty? |
| 23 | + raise "Code tracker registry is not empty" |
| 24 | + end |
27 | 25 |
|
28 |
| - # Test load something |
29 |
| - require 'open3' |
| 26 | + # Test load something |
| 27 | + require 'open3' |
30 | 28 |
|
31 |
| - if Datadog::DI.code_tracker.send(:registry).empty? |
32 |
| - raise "Code tracker did not add loaded file to registry" |
33 |
| - end |
| 29 | + if Datadog::DI.code_tracker.send(:registry).empty? |
| 30 | + raise "Code tracker did not add loaded file to registry" |
| 31 | + end |
| 32 | +
|
| 33 | + unless Datadog::DI.code_tracker.send(:registry).detect { |key, value| key =~ /open3.rb\\z/ } |
| 34 | + raise "Loaded script not found in code tracker registry" |
| 35 | + end |
| 36 | +
|
| 37 | + if Datadog.constants.sort != %i(DI VERSION) |
| 38 | + raise "Too many datadog components loaded at the end of execution: \#{Datadog.constants}" |
| 39 | + end |
| 40 | + SCRIPT |
| 41 | + |
| 42 | + context 'when loaded initially into a clean process' do |
| 43 | + it 'loads only DI code tracker' do |
| 44 | + out, status = Open3.capture2e('ruby', stdin_data: BOOTSTRAP_SCRIPT) |
| 45 | + unless status.exitstatus == 0 |
| 46 | + fail("Test script failed with exit status #{status.exitstatus}:\n#{out}") |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + context 'when entire library is loaded after di bootstrapper' do |
| 52 | + it 'keeps the mappings in code tracker prior to datadog load' do |
| 53 | + script = <<-SCRIPT |
| 54 | + #{BOOTSTRAP_SCRIPT} |
| 55 | +
|
| 56 | + require 'datadog' |
34 | 57 |
|
| 58 | + # Should still have the open3 entry in code tracker |
35 | 59 | unless Datadog::DI.code_tracker.send(:registry).detect { |key, value| key =~ /open3.rb\\z/ }
|
36 | 60 | raise "Loaded script not found in code tracker registry"
|
37 | 61 | end
|
38 | 62 |
|
39 |
| - if Datadog.constants.sort != %i(DI VERSION) |
40 |
| - raise "Too many datadog components loaded at the end of execution: \#{Datadog.constants}" |
| 63 | + unless defined?(Datadog::Tracing) |
| 64 | + raise "Expected Datadog::Tracing to be defined after datadog was loaded" |
41 | 65 | end
|
42 | 66 | SCRIPT
|
43 | 67 | out, status = Open3.capture2e('ruby', stdin_data: script)
|
|
0 commit comments