Skip to content

Commit 99aff41

Browse files
committed
Fix flaky sampler spec
1 parent 915399f commit 99aff41

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

spec/datadog/appsec/api_security/lru_cache_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
let(:lru_cache) { described_class.new(3) }
4848

4949
it 'stores a key-value pair' do
50-
expect { lru_cache.store(:key, 'value') }.to
51-
change { lru_cache[:key] }.from(nil).to('value')
50+
expect { lru_cache.store(:key, 'value') }.to change { lru_cache[:key] }
51+
.from(nil).to('value')
5252
end
5353

5454
it 'overwrites existing values' do
5555
lru_cache.store(:key, 'old-value')
5656

57-
expect { lru_cache.store(:key, 'new-value') }.to
58-
change { lru_cache[:key] }.from('old-value').to('new-value')
57+
expect { lru_cache.store(:key, 'new-value') }.to change { lru_cache[:key] }
58+
.from('old-value').to('new-value')
5959
end
6060

6161
context 'when maximum size is reached' do

spec/datadog/appsec/api_security/sampler_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
example.run
2020
ensure
2121
Datadog.configuration.reset!
22+
described_class.reset!
2223
end
2324

2425
context 'when called for the first time' do
2526
it 'returns a new sampler instance' do
26-
expect { described_class.thread_local }.to change { Thread.current.thread_variable_get(:__sampler_key__) }
27-
.from(nil).to(be_a(described_class))
27+
# NOTE: Isolating the sampler in a separate thread to avoid flakiness
28+
thread = Thread.new do
29+
expect { described_class.thread_local }.to change { Thread.current.thread_variable_get(:__sampler_key__) }
30+
.from(nil).to(be_a(described_class))
31+
end
32+
33+
thread.join
2834
end
2935
end
3036

0 commit comments

Comments
 (0)