|
32 | 32 | context 'when not using JRuby' do
|
33 | 33 | before { stub_const('RUBY_ENGINE', 'ruby') }
|
34 | 34 |
|
35 |
| - context 'and \'google-protobuf\'' do |
| 35 | + context 'when the profiling native library fails to be loaded with a exception' do |
| 36 | + let(:loaderror) do |
| 37 | + begin |
| 38 | + raise LoadError, 'Simulated require failure' |
| 39 | + rescue LoadError => e |
| 40 | + e |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + before do |
| 45 | + expect(described_class).to receive(:try_loading_native_library).and_return([false, loaderror]) |
| 46 | + end |
| 47 | + |
| 48 | + it { is_expected.to include 'error loading the profiling native extension' } |
| 49 | + end |
| 50 | + |
| 51 | + context "when the profiling native library fails to be loaded but there's no exception" do |
| 52 | + before do |
| 53 | + expect(described_class).to receive(:try_loading_native_library).and_return [false, nil] |
| 54 | + end |
| 55 | + |
| 56 | + it { is_expected.to include 'profiling native extension did not load correctly' } |
| 57 | + end |
| 58 | + |
| 59 | + context "when the profiling native library is available and 'google-protobuf'" do |
| 60 | + before do |
| 61 | + expect(described_class).to receive(:try_loading_native_library).and_return [true, nil] |
| 62 | + end |
| 63 | + |
36 | 64 | context 'is not available' do
|
37 | 65 | include_context 'loaded gems', :'google-protobuf' => nil
|
38 | 66 |
|
|
101 | 129 | it { is_expected.to be false }
|
102 | 130 |
|
103 | 131 | it 'logs a warning' do
|
104 |
| - expect(Kernel).to receive(:warn).with(/Error while loading/) |
| 132 | + expect(Kernel).to receive(:warn).with(/Error while loading google-protobuf/) |
105 | 133 |
|
106 | 134 | protobuf_loaded_successfully?
|
107 | 135 | end
|
|
113 | 141 | it { is_expected.to be true }
|
114 | 142 | end
|
115 | 143 | end
|
| 144 | + |
| 145 | + describe '::try_loading_native_library' do |
| 146 | + subject(:try_loading_native_library) { described_class.send(:try_loading_native_library) } |
| 147 | + |
| 148 | + let(:native_extension_require) { "ddtrace_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}" } |
| 149 | + |
| 150 | + context 'when the profiling native library loads successfully' do |
| 151 | + before do |
| 152 | + expect(described_class) |
| 153 | + .to receive(:require) |
| 154 | + .with(native_extension_require) |
| 155 | + stub_const('Datadog::Profiling::NativeExtension', double(native_working?: true)) |
| 156 | + end |
| 157 | + |
| 158 | + it { is_expected.to eq [true, nil] } |
| 159 | + end |
| 160 | + |
| 161 | + context 'when the profiling native library fails to load with a LoadError' do |
| 162 | + before do |
| 163 | + expect(described_class).to receive(:require).with(native_extension_require).and_raise(loaderror) |
| 164 | + end |
| 165 | + |
| 166 | + let(:loaderror) { LoadError.new('Simulated require failure') } |
| 167 | + |
| 168 | + it { is_expected.to eq [false, loaderror] } |
| 169 | + end |
| 170 | + |
| 171 | + context 'when the profiling native library fails to load with a different error' do |
| 172 | + before do |
| 173 | + expect(described_class).to receive(:require).with(native_extension_require).and_raise(error) |
| 174 | + end |
| 175 | + |
| 176 | + let(:error) { StandardError.new('Simulated require failure') } |
| 177 | + |
| 178 | + it { is_expected.to eq [false, error] } |
| 179 | + end |
| 180 | + |
| 181 | + context 'when the profiling native library loads but does not install code correctly' do |
| 182 | + before do |
| 183 | + expect(described_class) |
| 184 | + .to receive(:require) |
| 185 | + .with(native_extension_require) |
| 186 | + stub_const('Datadog::Profiling::NativeExtension', double(native_working?: false)) |
| 187 | + end |
| 188 | + |
| 189 | + it { is_expected.to eq [false, nil] } |
| 190 | + end |
| 191 | + end |
116 | 192 | end
|
0 commit comments