|
251 | 251 | persistent_file&.unlink |
252 | 252 | end |
253 | 253 |
|
| 254 | + it 'refreshes persistence when Rails loads the webhook secret after initial setup' do |
| 255 | + original_token = ENV['FLIPPER_CLOUD_TOKEN'] |
| 256 | + original_secret = ENV['FLIPPER_CLOUD_SYNC_SECRET'] |
| 257 | + original_interval = ENV['FLIPPER_CLOUD_SYNC_INTERVAL'] |
| 258 | + ENV['FLIPPER_CLOUD_TOKEN'] = 'asdf' |
| 259 | + ENV.delete('FLIPPER_CLOUD_SYNC_SECRET') |
| 260 | + ENV['FLIPPER_CLOUD_SYNC_INTERVAL'] = '10' |
| 261 | + persistent_file = Tempfile.new("flipper-cloud") |
| 262 | + persistent_file.close |
| 263 | + persistent = Flipper::Adapters::PStore.new(persistent_file.path) |
| 264 | + Flipper.new(persistent).disable(:search) |
| 265 | + Flipper.configure { |config| config.adapter { persistent } } |
| 266 | + |
| 267 | + described_class.set_default |
| 268 | + ENV['FLIPPER_CLOUD_SYNC_SECRET'] = 'secret' |
| 269 | + ENV['FLIPPER_CLOUD_SYNC_INTERVAL'] = '30' |
| 270 | + described_class.set_default(instrumenter: Flipper::Instrumenters::Memory.new) |
| 271 | + expect(Flipper::Poller).not_to receive(:get) |
| 272 | + instance = Flipper.configuration.default |
| 273 | + expect(instance.enabled?(:search)).to be(false) |
| 274 | + Flipper.new(persistent).enable(:search) |
| 275 | + |
| 276 | + now = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) |
| 277 | + allow(Process).to receive(:clock_gettime).and_call_original |
| 278 | + allow(Process).to receive(:clock_gettime).with(Process::CLOCK_MONOTONIC, :second).and_return(now + 20) |
| 279 | + expect(instance.enabled?(:search)).to be(false) |
| 280 | + allow(Process).to receive(:clock_gettime).with(Process::CLOCK_MONOTONIC, :second).and_return(now + 31) |
| 281 | + expect(instance.enabled?(:search)).to be(true) |
| 282 | + ensure |
| 283 | + ENV['FLIPPER_CLOUD_TOKEN'] = original_token |
| 284 | + ENV['FLIPPER_CLOUD_SYNC_SECRET'] = original_secret |
| 285 | + ENV['FLIPPER_CLOUD_SYNC_INTERVAL'] = original_interval |
| 286 | + persistent_file&.unlink |
| 287 | + end |
| 288 | + |
254 | 289 | it 'keeps configured behavioral adapters outside memory reads' do |
255 | 290 | original_token = ENV['FLIPPER_CLOUD_TOKEN'] |
256 | 291 | ENV['FLIPPER_CLOUD_TOKEN'] = 'asdf' |
|
0 commit comments