|
301 | 301 | watched_files = plugin.watcher.watch.watched_files_collection
|
302 | 302 | expect( watched_files ).to be_empty
|
303 | 303 | end
|
| 304 | + end |
304 | 305 |
|
305 |
| - private |
| 306 | + describe 'sincedb cleanup' do |
306 | 307 |
|
307 |
| - def wait_for_start_processing(run_thread, timeout: 1.0) |
308 |
| - begin |
309 |
| - Timeout.timeout(timeout) do |
310 |
| - sleep(0.01) while run_thread.status != 'sleep' |
311 |
| - sleep(timeout) unless plugin.queue |
312 |
| - end |
313 |
| - rescue Timeout::Error |
314 |
| - raise "plugin did not start processing (timeout: #{timeout})" unless plugin.queue |
315 |
| - else |
316 |
| - raise "plugin did not start processing" unless plugin.queue |
| 308 | + let(:options) do |
| 309 | + super.merge( |
| 310 | + 'sincedb_path' => sincedb_path, |
| 311 | + 'sincedb_clean_after' => '1.0 seconds', |
| 312 | + 'sincedb_write_interval' => 0.25, |
| 313 | + 'stat_interval' => 0.1, |
| 314 | + ) |
| 315 | + end |
| 316 | + |
| 317 | + let(:sincedb_path) { "#{temp_directory}/.sincedb" } |
| 318 | + |
| 319 | + let(:sample_file) { File.join(temp_directory, "sample.txt") } |
| 320 | + |
| 321 | + before do |
| 322 | + plugin.register |
| 323 | + @run_thread = Thread.new(plugin) do |plugin| |
| 324 | + Thread.current.abort_on_exception = true |
| 325 | + plugin.run queue |
317 | 326 | end
|
| 327 | + |
| 328 | + File.open(sample_file, 'w') { |fd| fd.write("line1\nline2\n") } |
| 329 | + |
| 330 | + wait_for_start_processing(@run_thread) |
318 | 331 | end
|
319 | 332 |
|
320 |
| - def wait_for_file_removal(path, timeout: 3 * interval) |
321 |
| - wait(timeout).for { File.exist?(path) }.to be_falsey |
| 333 | + after { plugin.stop } |
| 334 | + |
| 335 | + it 'cleans up sincedb entry' do |
| 336 | + wait_for_file_removal(sample_file) # watched discovery |
| 337 | + |
| 338 | + sincedb_content = File.read(sincedb_path).strip |
| 339 | + expect( sincedb_content ).to_not be_empty |
| 340 | + |
| 341 | + Stud.try(3.times) do |
| 342 | + sleep(1.5) # > sincedb_clean_after |
| 343 | + |
| 344 | + sincedb_content = File.read(sincedb_path).strip |
| 345 | + expect( sincedb_content ).to be_empty |
| 346 | + end |
322 | 347 | end
|
323 | 348 |
|
324 | 349 | end
|
| 350 | + |
| 351 | + private |
| 352 | + |
| 353 | + def wait_for_start_processing(run_thread, timeout: 1.0) |
| 354 | + begin |
| 355 | + Timeout.timeout(timeout) do |
| 356 | + sleep(0.01) while run_thread.status != 'sleep' |
| 357 | + sleep(timeout) unless plugin.queue |
| 358 | + end |
| 359 | + rescue Timeout::Error |
| 360 | + raise "plugin did not start processing (timeout: #{timeout})" unless plugin.queue |
| 361 | + else |
| 362 | + raise "plugin did not start processing" unless plugin.queue |
| 363 | + end |
| 364 | + end |
| 365 | + |
| 366 | + def wait_for_file_removal(path, timeout: 3 * interval) |
| 367 | + wait(timeout).for { File.exist?(path) }.to be_falsey |
| 368 | + end |
325 | 369 | end
|
0 commit comments