Skip to content

Commit b9290c1

Browse files
committed
Allow for parralel execution of cucumber tests
1 parent b1682ef commit b9290c1

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

features/support/env.rb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
require 'vimrunner'
2+
require 'securerandom'
23
require_relative "../../rubylib/vdebug"
34

4-
PHP_INI = File.expand_path('../../../.travis.php.ini', __FILE__)
5+
begin
6+
TMP_DIR = "tmpspace_#{SecureRandom::hex(3)}"
7+
PHP_INI = File.expand_path('../../../.travis.php.ini', __FILE__)
58

6-
Before do
7-
Dir.mkdir 'tmpspace' unless Dir.exists? 'tmpspace'
8-
Dir.chdir 'tmpspace'
9+
Before do
10+
Dir.mkdir TMP_DIR unless Dir.exists? TMP_DIR
11+
Dir.chdir TMP_DIR
912

10-
# Setup plugin in the Vim instance
11-
plugin_path = File.expand_path('../../..', __FILE__)
12-
vim.add_plugin(plugin_path, 'plugin/vdebug.vim')
13-
end
13+
# Setup plugin in the Vim instance
14+
plugin_path = File.expand_path('../../..', __FILE__)
15+
vim.add_plugin(plugin_path, 'plugin/vdebug.vim')
16+
end
17+
18+
After do
19+
kill_vim
20+
Dir.chdir '..'
21+
system "rm -r #{TMP_DIR}"
22+
end
1423

15-
After do
16-
kill_vim
17-
Dir.chdir '..'
18-
system "rm -r tmpspace"
24+
rescue Exception
25+
system "rm -r #{TMP_DIR}"
26+
raise
1927
end

features/support/helpers.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def kill_vim
1313
if @vim
1414
@vim.kill
1515
@vim = nil
16-
@vdebug = nil
16+
if @vdebug
17+
@vdebug.remove_lock_file!
18+
@vdebug = nil
19+
end
1720
end
1821
end
1922
end

rubylib/vdebug.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
require 'securerandom'
2+
13
class Vdebug
24
class BufferNotFound < StandardError; end;
35

46
attr_reader :vim
57

68
def initialize(vim)
9+
@lock_file = "../vdebug.lock"
10+
@instance_id = SecureRandom::hex(3)
711
@vim = vim
812
end
913

1014
def start_listening
15+
write_lock_file!
1116
clear_buffer_cache!
1217
vim.server.remote_send ":python debugger.run()<CR>"
1318
sleep 1
@@ -103,7 +108,22 @@ def status
103108
/Status: (\S+)/.match(status_window_content)[1]
104109
end
105110

111+
def remove_lock_file!
112+
if File.exists?(@lock_file) && File.read(@lock_file) == @instance_id
113+
puts "Deleting lock file for #{@instance_id}"
114+
File.delete(@lock_file)
115+
end
116+
end
117+
106118
protected
119+
def write_lock_file!
120+
while File.exists?(@lock_file)
121+
sleep 0.1
122+
end
123+
puts "Creating lock file for #{@instance_id}"
124+
File.write(@lock_file, @instance_id)
125+
end
126+
107127
def fetch_buffer_content(name)
108128
bufnum = buffers.invert.fetch(name)
109129
vim.echo(%Q{join(getbufline(#{bufnum}, 1, "$"), "\\n")})

0 commit comments

Comments
 (0)