Skip to content

Commit 604cc62

Browse files
committed
Make feature tests more reliable
1 parent 96b51f3 commit 604cc62

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

Vagrantfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1515

1616
# Forward the vdebug server port to the host
1717
config.vm.network :forwarded_port, guest: 9000, host: 9000
18+
config.vm.network :forwarded_port, guest: 5900, host: 5901
1819

1920
# Use a shell script to provision
2021
config.vm.provision :shell, path: "bootstrap.sh"

rubylib/vdebug.rb

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
class Vdebug
44
class BufferNotFound < StandardError; end;
55

6-
attr_reader :vim
6+
attr_reader :vim, :watch_win_marker
77

88
def initialize(vim)
99
@lock_file = "../vdebug.lock"
1010
@instance_id = SecureRandom::hex(3)
1111
@vim = vim
12+
@watch_win_marker = option_value("marker_default")
1213
end
1314

1415
def start_listening
@@ -75,8 +76,8 @@ def watch_window_content
7576

7677
def watch_vars
7778
watch_lines = watch_window_content.split("\n")[4..-1]
78-
Hash[watch_lines.join("").split('|').map { |v|
79-
v[3..-1].split("=", 2).map(&:strip)
79+
p Hash[watch_lines.join("").split('|').map { |v|
80+
v.gsub(/^.*#{watch_win_marker}/, "").split("=", 2).map(&:strip)
8081
}]
8182
end
8283

@@ -109,19 +110,30 @@ def status
109110
end
110111

111112
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)
113+
if File.exists?(@lock_file)
114+
lock_file_id = File.read(@lock_file)
115+
if lock_file_id == @instance_id
116+
puts "Releasing lock (#{@instance_id})"
117+
File.delete(@lock_file)
118+
else
119+
puts "Lock file #{@lock_file} is for instance #{lock_file_id}, whereas current instance is #{@instance_id}"
120+
end
115121
end
116122
end
117123

118124
protected
119125
def write_lock_file!
120-
while File.exists?(@lock_file)
121-
puts "Waiting for lock to be removed"
122-
sleep 0.1
126+
if File.exists?(@lock_file)
127+
128+
puts "Waiting for vdebug lock to be released"
129+
i = 0
130+
while File.exists?(@lock_file)
131+
sleep 0.5
132+
i += 1
133+
raise "Failed to acquire vdebug lock" if i >= 20
134+
end
123135
end
124-
puts "Creating lock file for #{@instance_id}"
136+
puts "Acquiring vdebug lock (#{@instance_id})"
125137
File.write(@lock_file, @instance_id)
126138
end
127139

@@ -140,4 +152,8 @@ def fetch_buffers
140152
end
141153
Hash[names.compact]
142154
end
155+
156+
def option_value(name)
157+
vim.echo("g:vdebug_options['#{name}']")
158+
end
143159
end

spec/vdebug_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
@vdebug = Vdebug.new vim
99
end
1010

11+
after do
12+
@vdebug.remove_lock_file!
13+
end
14+
1115
let(:vimrunner) { @vim }
1216
let(:vdebug) { @vdebug }
1317

0 commit comments

Comments
 (0)