Skip to content

Commit

Permalink
specs: improve isolation with per-spec temp data directory
Browse files Browse the repository at this point in the history
  • Loading branch information
yaauie committed May 16, 2018
1 parent e072e74 commit 5c0b835
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,20 @@ def puts(payload)
c.include LogStashHelper
c.extend LogStashHelper

c.before(:each) do
# TODO: commented out on post-merged in master - the logger has moved to log4j
#
#
# Force Cabin to always have a JSON subscriber. The main purpose of this
# is to catch crashes in json serialization for our logs. JSONIOThingy
# exists to validate taht what LogStash::Logging::JSON emits is always
# valid JSON.
# jsonvalidator = JSONIOThingy.new
# allow(Cabin::Channel).to receive(:new).and_wrap_original do |m, *args|
# logger = m.call(*args)
# logger.level = :debug
# logger.subscribe(LogStash::Logging::JSON.new(jsonvalidator))
#
# logger
# end

# Some tests mess with the settings. This ensures one test cannot pollute another
LogStash::SETTINGS.reset

LogStash::SETTINGS.set("queue.type", "persisted")
LogStash::SETTINGS.set("queue.page_capacity", 1024 * 1024)
LogStash::SETTINGS.set("queue.max_events", 250)
# Some tests mess with LogStash::SETTINGS, and data on the filesystem can leak state
# from one spec to another; run each spec with its own temporary data directory for `path.data`
c.around(:each) do |example|
Dir.mktmpdir do |temp_directory|
# Some tests mess with the settings. This ensures one test cannot pollute another
LogStash::SETTINGS.reset

LogStash::SETTINGS.set("queue.type", "persisted")
LogStash::SETTINGS.set("queue.page_capacity", 1024 * 1024)
LogStash::SETTINGS.set("queue.max_events", 250)
LogStash::SETTINGS.set("path.data", temp_directory)

example.run
end
end
end

Expand Down

0 comments on commit 5c0b835

Please sign in to comment.