Make flaky tests reliable (#1978)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jack Bates · committed by GitHub · parent 69e7eab · Browse files · 2 files·+75 added−118 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+75 added−118 removed
- tests:+72 added−117 removed
- other:+3 added−1 removed
Provenance
- Commit
cf04753- Tree
908b268- Author
Jack Bates <jack@nottheoilrig.com>- Committer
GitHub <noreply@github.com>- Parent
69e7eab
2 files changed+75 added−118 removed
modified:test/test_go.rb+72 added-117 removed
107 unmodified lines108 system('tmux', 'setb', str, ';', 'pasteb', '-t', win, ';', 'send-keys', '-t', win, 'Enter')109 end110 111 def capture112- go(%W[capture-pane -p -t #{win}]).reverse.drop_while(&:empty?).reverse112+ go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse113 end114 115 def until(refresh = false)116 lines = nil136 unmodified lines253 end254 255 def test_fzf_default_command256 tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter257- tmux.until { |lines| lines.last =~ /^>/ }257+ tmux.until { |lines| lines[-3] == '> hello' }258 259 tmux.send_keys :Enter260 assert_equal 'hello', readonce.chomp261 end265 unmodified lines527 end528 529 def test_expect530 test = lambda do |key, feed, expected = key|531- tmux.send_keys "seq 1 100 | #{fzf(:expect, key)}; sync", :Enter531+ tmux.send_keys "seq 1 100 | #{fzf(:expect, key)}", :Enter532 tmux.until { |lines| lines[-2].include?('100/100') }533 tmux.send_keys '55'534 tmux.until { |lines| lines[-2].include?('1/100') }535 tmux.send_keys(*feed)343 unmodified lines879 end880 opts = "--history=#{history_file} --history-size=4"881 input = %w[00 11 22 33 44].map { |e| e + $INPUT_RECORD_SEPARATOR }882 input.each do |keys|883+ tmux.prepare884 tmux.send_keys "seq 100 | #{fzf(opts)}", :Enter885 tmux.until { |lines| lines[-2].include?('100/100') }886 tmux.send_keys keys887 tmux.until { |lines| lines[-2].include?('1/100') }888 tmux.send_keys :Enter888- readonce889 end890- assert_equal input[1..-1], File.readlines(history_file)890+ wait { File.exist?(history_file) && File.readlines(history_file) == input[1..-1] }891 892 # Update history entries (not changed on disk)893 tmux.send_keys "seq 100 | #{fzf(opts)}", :Enter894 tmux.until { |lines| lines[-2].include?('100/100') }11 unmodified lines906 tmux.until { |lines| lines[-1].end_with?('> 31') }907 tmux.send_keys 0908 tmux.until { |lines| lines[-1].end_with?('> 310') }909 tmux.send_keys :Enter910- readonce911- assert_equal %w[22 33 44 310].map { |e| e + $INPUT_RECORD_SEPARATOR }, File.readlines(history_file)910+ wait { File.exist?(history_file) && File.readlines(history_file) == %w[22 33 44 310].map { |e| e + $INPUT_RECORD_SEPARATOR } }911 912 # Respect --bind option913 tmux.send_keys "seq 100 | #{fzf(opts + ' --bind ctrl-p:next-history,ctrl-n:previous-history')}", :Enter914 tmux.until { |lines| lines[-2].include?('100/100') }6 unmodified lines921 922 def test_execute923 output = '/tmp/fzf-test-execute'924 opts = %[--bind "alt-a:execute(echo /{}/ >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}"]926- wait = ->(exp) { tmux.until { |lines| lines[-2].include?(exp) } }925 writelines(tempname, %w[foo'bar foo"bar foo$bar])928- tmux.send_keys "cat #{tempname} | #{fzf(opts)}; sync", :Enter929- wait['3/3']926+ tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter927+ tmux.until { |lines| lines[-2] == ' 3/3' }928 tmux.send_keys :Escape, :a931- wait['/3']929 tmux.send_keys :Escape, :a933- wait['/3']930 tmux.send_keys :Up931 tmux.send_keys :Escape, :b936- wait['/3']932 tmux.send_keys :Escape, :b938- wait['/3']933 tmux.send_keys :Up934 tmux.send_keys :C941- wait['3/3']935 tmux.send_keys 'barfoo'943- wait['0/3']936+ tmux.until { |lines| lines[-2] == ' 0/3' }937 tmux.send_keys :Escape, :a945- wait['/3']938 tmux.send_keys :Escape, :b947- wait['/3']948- tmux.send_keys :Enter949- readonce950- assert_equal %w[/foo'bar/ /foo'bar/951- /foo"barfoo"bar/ /foo"barfoo"bar/952- /foo$barfoo$barfoo$bar/],953- File.readlines(output).map(&:chomp)939+ wait do940+ File.exist?(output) && File.readlines(output).map(&:chomp) == %w[941+ /foo'bar/ /foo'bar/942+ /foo"barfoo"bar/ /foo"barfoo"bar/943+ /foo$barfoo$barfoo$bar/944+ ]945+ end946 ensure947 begin948 File.unlink(output)949 rescue StandardError2 unmodified lines952 end953 954 def test_execute_multi955 output = '/tmp/fzf-test-execute-multi'964- opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output}; sync)"]956+ opts = %[--multi --bind "alt-a:execute-multi(echo {}/{+} >> #{output})"]957 writelines(tempname, %w[foo'bar foo"bar foo$bar foobar])958 tmux.send_keys "cat #{tempname} | #{fzf(opts)}", :Enter959 tmux.until { |lines| lines[-2].include?('4/4') }960 tmux.send_keys :Escape, :a2 unmodified lines963 tmux.send_keys :Escape, :a964 tmux.until { |lines| lines[-2].include?('/4') }965 tmux.send_keys :Tab, :Tab966 tmux.send_keys :Escape, :a975- tmux.until { |lines| lines[-2].include?('/4') }976- tmux.send_keys :Enter977- tmux.prepare978- readonce979- assert_equal [%(foo'bar/foo'bar),980- %(foo'bar foo"bar foo$bar/foo'bar foo"bar foo$bar),981- %(foo'bar foo"bar foobar/foo'bar foo"bar foobar)],982- File.readlines(output).map(&:chomp)967+ wait do968+ File.exist?(output) && File.readlines(output).map(&:chomp) == [969+ %(foo'bar/foo'bar),970+ %(foo'bar foo"bar foo$bar/foo'bar foo"bar foo$bar),971+ %(foo'bar foo"bar foobar/foo'bar foo"bar foobar)972+ ]973+ end974 ensure975 begin976 File.unlink(output)977 rescue StandardError28 unmodified lines1006 1007 tmux.send_keys :Tab1008 execute.call1009 1019- tmux.send_keys :Enter1020- tmux.prepare1021- readonce1022-1023- assert_equal [1024- %(foo bar/foo bar/bar/bar),1025- %(123 456/foo bar/456/bar),1026- %(123 456 foo bar/foo bar/456 bar/bar)1027- ], File.readlines(output).map(&:chomp)1010+ wait do1011+ File.exist?(output) && File.readlines(output).map(&:chomp) == [1012+ %(foo bar/foo bar/bar/bar),1013+ %(123 456/foo bar/456/bar),1014+ %(123 456 foo bar/foo bar/456 bar/bar)1015+ ]1016+ end1017 rescue StandardError1018 begin1019 File.unlink(output)1020 rescue StandardError9 unmodified lines1030 rescue StandardError1031 nil1032 end1033 writelines(tempname,1045- ['#!/usr/bin/env bash', "echo $1 / $2 > #{output}", 'sync'])1034+ ['#!/usr/bin/env bash', "echo $1 / $2 > #{output}"])1035 system("chmod +x #{tempname}")1036 1037 tmux.send_keys "echo foo | SHELL=#{tempname} fzf --bind 'enter:execute:{}bar'", :Enter1038 tmux.until { |lines| lines[-2].include?('1/1') }1039 tmux.send_keys :Enter1051- tmux.until { |lines| lines[-2].include?('1/1') }1052- tmux.send_keys 'C-c'1053- tmux.prepare1054- assert_equal ["-c / 'foo'bar"], File.readlines(output).map(&:chomp)1040+ wait { File.exist?(output) && File.readlines(output).map(&:chomp) == ["-c / 'foo'bar"] }1041 ensure1042 begin1043 File.unlink(output)1044 rescue StandardError329 unmodified lines1374 assert_equal '3', readonce.chomp1375 end1376 1377 def test_pointer1392- pointer = '>>'1393- tmux.send_keys "seq 10 | #{fzf("--pointer '#{pointer}'")}", :Enter1378+ tmux.send_keys "seq 10 | #{fzf("--pointer '>>'")}", :Enter1394- tmux.until { |lines| lines[-2] == ' 10/10' }1395- lines = tmux.capture1379 # Assert that specified pointer is displayed1397- assert_equal "#{pointer} 1", lines[-3]1380+ tmux.until { |lines| lines[-3] == '>> 1' }1381 end1382 1383 def test_pointer_with_jump1401- pointer = '>>'1402- tmux.send_keys "seq 10 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump' --pointer '#{pointer}'")}", :Enter1384+ tmux.send_keys "seq 10 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump' --pointer '>>'")}", :Enter1385 tmux.until { |lines| lines[-2] == ' 10/10' }1386 tmux.send_keys 'C-j'1387 # Correctly padded jump label should appear1388 tmux.until { |lines| lines[-7] == '5 5' }1389 tmux.until { |lines| lines[-8] == ' 6' }1390 tmux.send_keys '5'1409- lines = tmux.capture1391 # Assert that specified pointer is displayed1411- assert_equal "#{pointer} 5", lines[-7]1392+ tmux.until { |lines| lines[-7] == '>> 5' }1393 end1394 1395 def test_marker1415- marker = '>>'1416- tmux.send_keys "seq 10 | #{fzf("--multi --marker '#{marker}'")}", :Enter1396+ tmux.send_keys "seq 10 | #{fzf("--multi --marker '>>'")}", :Enter1397 tmux.until { |lines| lines[-2] == ' 10/10' }1398 tmux.send_keys :BTab1419- lines = tmux.capture1399 # Assert that specified marker is displayed1421- assert_equal " #{marker}1", lines[-3]1400+ tmux.until { |lines| lines[-3] == ' >>1' }1401 end1402 1403 def test_preview1404 tmux.send_keys %(seq 1000 | sed s/^2$// | #{FZF} -m --preview 'sleep 0.2; echo {{}-{+}}' --bind ?:toggle-preview), :Enter41 unmodified lines1446 nil1447 end1448 tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0), :Enter1449 tmux.until { |lines| lines.item_count == 100 && lines[1] == ' 100/100' && lines[2] == '> 1' }1471- tmux.until { |_| File.readlines(tempname).map(&:chomp) == %w[1] }1450+ wait { File.exist?(tempname) && File.readlines(tempname).map(&:chomp) == %w[1] }1451 tmux.send_keys :Down1452 tmux.until { |lines| lines[3] == '> 2' }1474- tmux.until { |_| File.readlines(tempname).map(&:chomp) == %w[1 2] }1453+ wait { File.exist?(tempname) && File.readlines(tempname).map(&:chomp) == %w[1 2] }1454 tmux.send_keys :Down1455 tmux.until { |lines| lines[4] == '> 3' }1477- tmux.until { |_| File.readlines(tempname).map(&:chomp) == %w[1 2 3] }1456+ wait { File.exist?(tempname) && File.readlines(tempname).map(&:chomp) == %w[1 2 3] }1457 end1458 1459 def test_preview_flags1460 tmux.send_keys %(seq 10 | sed 's/^/:: /; s/$/ /' |43 unmodified lines1504 tmux.send_keys "seq 10 | fzf --no-clear --inline-info --height 5 > #{tempname}", :Enter1505 prompt = '> < 10/10'1506 tmux.until { |lines| lines[-1] == prompt }1507 tmux.send_keys :Enter1529- tmux.until { |_| File.readlines(tempname).map(&:chomp) == %w[1] }1508+ wait { File.exist?(tempname) && File.readlines(tempname).map(&:chomp) == %w[1] }1509 tmux.until { |lines| lines[-1] == prompt }1510 end1511 1512 def test_info_hidden44 unmodified lines1557 end1558 1559 def test_accept_non_empty_with_empty_list1560 tmux.send_keys %(: | #{fzf('-q foo --print-query --bind enter:accept-non-empty')}), :Enter1582- tmux.until { |lines| lines[-2].strip == '0/0' }1561+ tmux.until { |lines| lines[-2] == ' 0/0' }1562 tmux.send_keys :Enter1563 # fzf will exit anyway since input list is empty1564 assert_equal %w[foo], readonce.split($INPUT_RECORD_SEPARATOR)1565 end161 unmodified lines1727 1728 def test_ctrl_t1729 set_var('FZF_CTRL_T_COMMAND', 'seq 100')1730 1752- retries do1753- tmux.prepare1754- tmux.send_keys 'C-t'1755- tmux.until { |lines| lines.item_count == 100 }1731+ tmux.prepare1732+ tmux.send_keys 'C-t'1733+ tmux.until { |lines| lines.item_count == 100 }1756- end1734 tmux.send_keys :Tab, :Tab, :Tab1735 tmux.until { |lines| lines.any_include?(' (3)') }1736 tmux.send_keys :Enter1737 tmux.until { |lines| lines.any_include?('1 2 3') }3 unmodified lines1741 def test_ctrl_t_unicode1742 writelines(tempname, ['fzf-unicode 테스트1', 'fzf-unicode 테스트2'])1743 set_var('FZF_CTRL_T_COMMAND', "cat #{tempname}")1744 1768- retries do1769- tmux.prepare1770- tmux.send_keys 'echo ', 'C-t'1771- tmux.until { |lines| lines.item_count == 2 }1745+ tmux.prepare1746+ tmux.send_keys 'echo ', 'C-t'1747+ tmux.until { |lines| lines.item_count == 2 }1772- end1748 tmux.send_keys 'fzf-unicode'1749 tmux.until { |lines| lines.match_count == 2 }1750 1751 tmux.send_keys '1'9 unmodified lines1761 tmux.send_keys :Tab1762 tmux.until { |lines| lines.select_count == 2 }1763 1764 tmux.send_keys :Enter1790- tmux.until { |lines| lines.join.match(/echo.*fzf-unicode.*1.*fzf-unicode.*2/) }1765+ tmux.until { |lines| lines.join =~ /echo .*fzf-unicode.*1.* .*fzf-unicode.*2/ }1766 tmux.send_keys :Enter1792- tmux.until { |lines| lines.any_include?(/^fzf-unicode.*1.*fzf-unicode.*2/) }1767+ tmux.until { |lines| lines[-1] == 'fzf-unicode 테스트1 fzf-unicode 테스트2' }1768 end1769 1770 def test_alt_c1796- lines = retries do1797- tmux.prepare1798- tmux.send_keys :Escape, :c1799- tmux.until { |lines| lines.match_count > 0 }1771+ tmux.prepare1772+ tmux.send_keys :Escape, :c1773+ lines = tmux.until { |lines| lines.match_count > 0 }1800- end1774 expected = lines.reverse.find { |l| l.start_with?('>') }[2..-1]1775 tmux.send_keys :Enter1776 tmux.prepare1777 tmux.send_keys :pwd, :Enter5 unmodified lines1783 1784 tmux.prepare1785 tmux.send_keys 'cd /', :Enter1786 1814- retries do1815- tmux.prepare1816- tmux.send_keys :Escape, :c1817- tmux.until { |lines| lines.item_count == 1 }1787+ tmux.prepare1788+ tmux.send_keys :Escape, :c1789+ tmux.until { |lines| lines.item_count == 1 }1818- end1790 tmux.send_keys :Enter1791 1792 tmux.prepare1793 tmux.send_keys :pwd, :Enter12 unmodified lines1806 tmux.send_keys 'echo 3rd', :Enter1807 tmux.prepare1808 end1809 tmux.send_keys 'echo 4th', :Enter1839- retries do1840- tmux.prepare1841- tmux.send_keys 'C-r'1842- tmux.until { |lines| lines.match_count > 0 }1810+ tmux.prepare1811+ tmux.send_keys 'C-r'1812+ tmux.until { |lines| lines.match_count > 0 }1843- end1813 tmux.send_keys 'e3d'1814 # Duplicates removed: 3d (1) + 3rd (1) => 2 matches1815 tmux.until { |lines| lines.match_count == 2 }1816 tmux.until { |lines| lines[-3].end_with?('echo 3d') }7 unmodified lines1824 1825 def test_ctrl_r_multiline1826 tmux.send_keys 'echo "foo', :Enter, 'bar"', :Enter1827 tmux.until { |lines| lines[-2..-1] == %w[foo bar] }1859- retries do1860- tmux.prepare1861- tmux.send_keys 'C-r'1862- tmux.until { |lines| lines[-1] == '>' }1828+ tmux.prepare1829+ tmux.send_keys 'C-r'1830+ tmux.until { |lines| lines[-1] == '>' }1863- end1831 tmux.send_keys 'foo bar'1832 tmux.until { |lines| lines[-3].end_with?('bar"') }1833 tmux.send_keys :Enter1834 tmux.until { |lines| lines[-1].end_with?('bar"') }1 unmodified line1836 tmux.until { |lines| lines[-2..-1] == %w[foo bar] }1837 end1838 1839 def test_ctrl_r_abort1873- skip("doesn't restore the original line when search is aborted pre Bash 4") if shell == :bash && /(?<= version )\d+/.match(`#{Shell.bash} --version`).to_s.to_i < 41840+ skip("doesn't restore the original line when search is aborted pre Bash 4") if shell == :bash && `#{Shell.bash} --version`[/(?<= version )\d+/].to_i < 41841 %w[foo ' "].each do |query|1875- retries do1876- tmux.prepare1877- tmux.send_keys :Space, 'C-e', 'C-u', query1878- tmux.until { |lines| lines[-1].start_with?(query) }1879- tmux.send_keys 'C-r'1880- tmux.until { |lines| lines[-1] == "> #{query}" }1842+ tmux.prepare1843+ tmux.send_keys :Enter, query1844+ tmux.until { |lines| lines[-1].start_with?(query) }1845+ tmux.send_keys 'C-r'1846+ tmux.until { |lines| lines[-1] == "> #{query}" }1881- end1847 tmux.send_keys 'C-g'1848 tmux.until { |lines| lines[-1].start_with?(query) }1849 end1850 end1886-1887- def retries(times = 3)1888- (times - 1).times do1889- begin1890- return yield1891- rescue RuntimeError # rubocop:todo Lint/SuppressedException1892- end1893- end1894- yield1895- end1851 end1852 1853 module CompletionTest1854 def test_file_completion23 unmodified lines1878 tmux.send_keys "'.fzf-home"1879 tmux.until { |lines| lines.count { |l| l.include?('.fzf-home') } > 1 }1880 tmux.send_keys :Enter1881 tmux.until(true) do |lines|1927- lines[-1].end_with?('.fzf-home')1882+ lines[-1] =~ %r{cat .*/\.fzf-home}1883 end1884 1885 # ~INVALID_USERNAME**<TAB>1886 tmux.send_keys 'C-u'131 unmodified lines2018 tmux.send_keys :Tab2019 tmux.until { |lines| lines.select_count == 2 }2020 2021 tmux.send_keys :Enter2067- tmux.until(true) { |lines| lines.any_include?('cat') }2022+ tmux.until(true) { |lines| lines[-1] =~ /cat .*fzf-unicode.*1.* .*fzf-unicode.*2/ }2023 tmux.send_keys :Enter2024 tmux.until { |lines| lines[-1].include?('test3test4') }2025 end2026 153 unmodified linesmodified:.travis.yml+3 added-1 removed
123456678910111213141516179 unmodified lineslanguage: goenv: GO111MODULE=onos: - linux - osxdist: bionic # For fish >= 2.3.0 string builtindist: bionicaddons: apt: packages: - fish - zsh sources: sourceline: ppa:fish-shell/release-3 homebrew: packages: - fish - tmux9 unmodified lines