Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable spec on circle ci #149

Merged
merged 6 commits into from
Feb 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/models/fluent_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ def list
# but long living caching causes mismatch with actual status e.g. user install plugin from console (without fluentd-ui)
# So our decision is that cache `gem list` in 3 seconds
Rails.cache.fetch(LIST_CACHE_KEY, expires_in: 3.seconds) do
output = `#{gem} list`
if $? && $?.exitstatus != 0 # NOTE: $? will be nil on CircleCI, so check $? at first
raise GemError, "failed command: `#{gem} list`"
last_status = $?
output = `#{gem} list 2>&1`
# https://github.com/fluent/fluentd-ui/pull/149#issuecomment-71954588
# Sometimes, $? wouldn't override with `#{gem} list` but I don't know why..
if $? && last_status != $? && $?.exitstatus != 0 # NOTE: $? will be nil on CircleCI, so check $? at first
raise GemError, "failed command: `#{gem} list` output: #{output}"
end
output.lines.to_a
end
Expand Down
6 changes: 5 additions & 1 deletion lib/fluentd-ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def self.fluentd_version
end

def self.data_dir
dir = ENV["FLUENTD_UI_DATA_DIR"].presence || ENV["HOME"] + "/.fluentd-ui/core_data"
if Rails.env.test?
dir = Rails.root.join("tmp", "core_data").to_s
else
dir = ENV["FLUENTD_UI_DATA_DIR"].presence || ENV["HOME"] + "/.fluentd-ui/core_data"
end
FileUtils.mkdir_p(dir) # ensure directory exists
dir
end
Expand Down
2 changes: 2 additions & 0 deletions spec/models/fluentd/agent/local_common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
CONF

before do
# other specs could be write in this dir, so clean that in `before`
FileUtils.rm_r daemon.agent.config_backup_dir, force: true
::Settings.max_backup_files_count.times do |i|
backpued_time = now - (i + 1).hours
FileUtils.touch File.join(daemon.agent.config_backup_dir , "#{backpued_time.strftime('%Y%m%d_%H%M%S')}.conf")
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@

# rspec 2.99
config.infer_spec_type_from_file_location!

config.after(:suite) do
FileUtils.rm_rf FluentdUI.data_dir
end
end