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

adding check to see if file is already cached before processing create file cache request #101

Merged
merged 1 commit into from
Jan 23, 2019
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: 9 additions & 0 deletions lib/method_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def self.remove_steps(file)
end
end

def self.is_file_cached(file)
BugDiver marked this conversation as resolved.
Show resolved Hide resolved
@@steps_map.each_pair do |step, info|
if info[:locations].any? { |loc| relative_filepath(loc[:file]).eql? relative_filepath(file) }
return true
end
end
return false
end

def self.multiple_implementation?(step_value)
@@steps_map[step_value][:locations].length > 1
end
Expand Down
6 changes: 4 additions & 2 deletions lib/processors/cache_file_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def cache_file_response(request)
ast = CodeParser.code_to_ast(request.content)
StaticLoader.reload_steps(f, ast)
elsif status == Messages::CacheFileRequest::FileStatus::CREATED
ast = CodeParser.code_to_ast File.read(f)
StaticLoader.reload_steps(f, ast)
if !Gauge::MethodCache.is_file_cached f
ast = CodeParser.code_to_ast File.read(f)
StaticLoader.reload_steps(f, ast)
end
elsif (status == Messages::CacheFileRequest::FileStatus::CLOSED) && File.file?(f)
ast = CodeParser.code_to_ast File.read(f)
StaticLoader.reload_steps(f, ast)
Expand Down
15 changes: 15 additions & 0 deletions spec/cache_file_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
expect(Gauge::MethodCache.valid_step? "foo").to eq true
end
end
context 'on Cache file request with CREATED status when file is already cached' do
before {
ast = Gauge::CodeParser.code_to_ast "step 'foo' do\n\tputs 'hello'\nend\n"
Gauge::StaticLoader.load_steps '/temp/foo.rb', ast
allow(File).to receive(:file?).with('/temp/foo.rb').and_return(true)
allow(File).to receive(:read).with('/temp/foo.rb').and_return("")
allow(message).to receive_message_chain(:cacheFileRequest, :filePath => '/temp/foo.rb')
allow(message).to receive_message_chain(:cacheFileRequest, :status => :CREATED)
allow(message).to receive(:messageId) {1}
}
it 'should reload step cache from file system' do
subject.process_cache_file_request(message)
expect(Gauge::MethodCache.valid_step? "foo").to eq true
end
end
context 'on Cache file request with CLOSED status' do
before {
ast = Gauge::CodeParser.code_to_ast "step 'foo' do\n\tputs 'hello'\nend\n"
Expand Down
14 changes: 14 additions & 0 deletions spec/method_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,18 @@
expect(step_info[0][:file]).to eq "/temp/foo1.bar"
end
end
context 'is_file_cached' do
before { subject.clear }
it 'should check if file is already cached' do
subject.add_step("step {}", {:step_text => "step <param>",:location => {:file => "/temp/foo.bar"}})
expect(subject.is_file_cached("/temp/foo.bar")).to eq true
expect(subject.is_file_cached("/tmp/foo1.bar")).to eq false
end
it 'should check if file is already cached in windows', :if => OS.windows? do
ENV['GAUGE_PROJECT_ROOT'] = "c:/temp"
subject.add_step("step {}", {:step_text => "step <param>",:location => {:file => "c:/temp/foo.bar"}})
expect(subject.is_file_cached("c:/temp/foo.bar")).to eq true
expect(subject.is_file_cached("c:/temp/foo1.bar")).to eq false
end
end
end