-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable new test helper for all feature specs * Refactor all feature specs
- Loading branch information
Showing
38 changed files
with
732 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,98 @@ | ||
require_relative 'output_file' | ||
# Can be updated to all feature repositories with | ||
# $ bin/test/reset_helpers | ||
|
||
module FileHelper | ||
def default_sleep_seconds | ||
Float(ENV.fetch('DEFAULT_SLEEP_SECONDS', 1)) | ||
module RetestHelper | ||
# COMMAND | ||
def launch_retest(command, sleep_for: Float(ENV.fetch('LAUNCH_SLEEP_SECONDS', 1.5))) | ||
require 'open3' | ||
@input, @output, @stderr, @wait_thr = Open3.popen3(command) | ||
@pid = @wait_thr[:pid] | ||
sleep sleep_for | ||
end | ||
|
||
def launch_sleep_seconds | ||
Float(ENV.fetch('LAUNCH_SLEEP_SECONDS', 1.5)) | ||
def end_retest | ||
@input&.close | ||
@stderr&.close | ||
@output&.close | ||
@wait_thr.exit | ||
end | ||
|
||
# ASSERTIONS | ||
def assert_output_matches(*expectations, max_retries: 5) | ||
retries = 0 | ||
wait_for = 0.1 | ||
output = "" | ||
begin | ||
output += read_output | ||
expectations.each { |expectation| assert_match(expectation, output) } | ||
rescue Minitest::Assertion => e | ||
raise e if retries >= max_retries | ||
retries += 1 | ||
sleep_seconds = wait_for ** -(wait_for * retries) | ||
sleep sleep_seconds | ||
retry | ||
end | ||
end | ||
|
||
def wait(sleep_seconds: default_sleep_seconds) | ||
sleep sleep_seconds | ||
# OUTPUT | ||
def read_output(output = @output) | ||
result = "" | ||
loop do | ||
result += output.read_nonblock(1024) | ||
rescue IO::WaitReadable, EOFError | ||
break | ||
end | ||
|
||
if block_given? | ||
yield result | ||
else | ||
result | ||
end | ||
end | ||
|
||
def modify_file(path, sleep_seconds: default_sleep_seconds) | ||
# INPUT | ||
def write_input(command, input: @input, sleep_for: 0.1) | ||
input.write(command) | ||
wait(sleep_for) | ||
end | ||
|
||
# FILE CHANGES | ||
def modify_file(path, sleep_for: default_sleep_seconds) | ||
return unless File.exist? path | ||
|
||
old_content = File.read(path) | ||
File.open(path, 'w') { |file| file.write old_content } | ||
|
||
sleep sleep_seconds | ||
wait(sleep_for) | ||
end | ||
|
||
def create_file(path, should_sleep: true, sleep_seconds: default_sleep_seconds) | ||
File.open(path, "w").tap(&:close) | ||
|
||
sleep sleep_seconds if should_sleep | ||
def create_file(path, content: "", sleep_for: default_sleep_seconds) | ||
File.open(path, "w") { |f| f.write(content) } | ||
wait(sleep_for) | ||
end | ||
|
||
def delete_file(path) | ||
def delete_file(path, sleep_for: 0) | ||
return unless File.exist? path | ||
|
||
File.delete path | ||
wait(sleep_for) | ||
end | ||
|
||
def rename_file(path, new_path) | ||
def rename_file(path, new_path, sleep_for: 0) | ||
return unless File.exist? path | ||
|
||
File.rename path, new_path | ||
wait(sleep_for) | ||
end | ||
end | ||
|
||
def launch_retest(command, sleep_seconds: launch_sleep_seconds) | ||
@rd, @input = IO.pipe | ||
@output = OutputFile.new | ||
@pid = Process.spawn command, out: @output.path, in: @rd | ||
sleep sleep_seconds | ||
end | ||
def default_sleep_seconds | ||
Float(ENV.fetch('DEFAULT_SLEEP_SECONDS', 1)) | ||
end | ||
|
||
def launch_sleep_seconds | ||
Float(ENV.fetch('LAUNCH_SLEEP_SECONDS', 1.5)) | ||
end | ||
|
||
def end_retest(file = nil, pid = nil) | ||
@output&.delete | ||
@rd&.close | ||
@input&.close | ||
if @pid | ||
Process.kill('SIGHUP', @pid) | ||
Process.detach(@pid) | ||
def wait(sleep_for = default_sleep_seconds) | ||
sleep sleep_for | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.