From 9bea841925bd7af0bea56aff109230f5c33195fe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Jul 2022 10:05:03 +0800 Subject: vim-patch:8.1.1855: another failing timer test Problem: Another failing timer test. Solution: Assert that timers are finished by the end of the test. Rename test functions to make them easier to find. https://github.com/vim/vim/commit/9a2fddcf04192a643dc97601d689c27f5bc5184f Use test_garbagecollect_now() in Test_timer_retain_partial() like Vim. --- src/nvim/testdir/runtest.vim | 13 +++++++------ src/nvim/testdir/test_timers.vim | 41 ++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 7060cab2e5..6b16e888a9 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -364,24 +364,25 @@ let s:flaky_tests = [ \ 'Test_cursorhold_insert()', \ 'Test_exit_callback_interval()', \ 'Test_map_timeout_with_timer_interrupt()', - \ 'Test_oneshot()', \ 'Test_out_cb()', - \ 'Test_paused()', \ 'Test_popup_and_window_resize()', \ 'Test_quoteplus()', \ 'Test_quotestar()', \ 'Test_reltime()', - \ 'Test_repeat_many()', - \ 'Test_repeat_three()', \ 'Test_state()', - \ 'Test_stop_all_in_callback()', \ 'Test_term_mouse_double_click_to_create_tab()', \ 'Test_term_mouse_multiple_clicks_to_visually_select()', \ 'Test_terminal_composing_unicode()', \ 'Test_terminal_redir_file()', \ 'Test_terminal_tmap()', + \ 'Test_timer_oneshot()', + \ 'Test_timer_paused()', + \ 'Test_timer_repeat_many()', + \ 'Test_timer_repeat_three()', + \ 'Test_timer_stop_all_in_callback()', + \ 'Test_timer_stop_in_callback()', + \ 'Test_timer_with_partial_callback()', \ 'Test_termwinscroll()', - \ 'Test_with_partial_callback()', \ ] " Locate Test_ functions and execute them. diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index e5b4bc23e8..f5e988e4d1 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -15,7 +15,7 @@ func MyHandlerWithLists(lists, timer) let x = string(a:lists) endfunc -func Test_oneshot() +func Test_timer_oneshot() let g:val = 0 let timer = timer_start(50, 'MyHandler') let slept = WaitFor('g:val == 1') @@ -27,7 +27,7 @@ func Test_oneshot() endif endfunc -func Test_repeat_three() +func Test_timer_repeat_three() let g:val = 0 let timer = timer_start(50, 'MyHandler', {'repeat': 3}) let slept = WaitFor('g:val == 3') @@ -39,7 +39,7 @@ func Test_repeat_three() endif endfunc -func Test_repeat_many() +func Test_timer_repeat_many() call timer_stopall() let g:val = 0 let timer = timer_start(50, 'MyHandler', {'repeat': -1}) @@ -51,7 +51,7 @@ func Test_repeat_many() call assert_inrange((has('mac') ? 1 : 2), LoadAdjust(5), g:val) endfunc -func Test_with_partial_callback() +func Test_timer_with_partial_callback() let g:val = 0 let meow = {'one': 1} function meow.bite(...) @@ -68,13 +68,13 @@ func Test_with_partial_callback() endif endfunc -func Test_retain_partial() +func Test_timer_retain_partial() call timer_start(50, function('MyHandlerWithLists', [['a']])) - call garbagecollect() + call test_garbagecollect_now() sleep 100m endfunc -func Test_info() +func Test_timer_info() let id = timer_start(1000, 'MyHandler') let info = id->timer_info() call assert_equal(id, info[0]['id']) @@ -93,7 +93,7 @@ func Test_info() call assert_equal([], timer_info(id)) endfunc -func Test_stopall() +func Test_timer_stopall() call timer_stopall() let id1 = timer_start(1000, 'MyHandler') let id2 = timer_start(2000, 'MyHandler') @@ -105,7 +105,7 @@ func Test_stopall() call assert_equal(0, len(info)) endfunc -func Test_paused() +func Test_timer_paused() let g:val = 0 let id = timer_start(50, 'MyHandler') @@ -138,7 +138,7 @@ func StopMyself(timer) endif endfunc -func Test_delete_myself() +func Test_timer_delete_myself() let g:called = 0 let t = timer_start(10, 'StopMyself', {'repeat': -1}) call WaitForAssert({-> assert_equal(2, g:called)}) @@ -157,16 +157,17 @@ func StopTimer2(timer) call timer_stop(g:timer1) endfunc -func Test_stop_in_callback() +func Test_timer_stop_in_callback() let g:timer1 = timer_start(10, 'StopTimer1') sleep 40m + call assert_equal(0, len(timer_info())) endfunc func StopTimerAll(timer) call timer_stopall() endfunc -func Test_stop_all_in_callback() +func Test_timer_stop_all_in_callback() call timer_stopall() let g:timer1 = timer_start(10, 'StopTimerAll') let info = timer_info() @@ -189,7 +190,7 @@ func InputCb(timer) call Resume() endfunc -func Test_input_in_timer() +func Test_timer_input_in_timer() let g:val = '' call timer_start(10, 'InputCb') call Standby(1000) @@ -242,7 +243,7 @@ func Interrupt(timer) call nvim_input("\") endfunc -func Test_peek_and_get_char() +func Test_timer_peek_and_get_char() if !has('unix') && !has('gui_running') return endif @@ -253,7 +254,7 @@ func Test_peek_and_get_char() eval intr->timer_stop() endfunc -func Test_getchar_zero() +func Test_timer_getchar_zero() if has('win32') && !has('gui_running') " Console: no low-level input return @@ -271,7 +272,7 @@ func Test_getchar_zero() call timer_stop(id) endfunc -func Test_ex_mode() +func Test_timer_ex_mode() " Function with an empty line. func Foo(...) @@ -282,9 +283,9 @@ func Test_ex_mode() call timer_stop(timer) endfunc -func Test_restore_count() +func Test_timer_restore_count() if !CanRunVimInTerminal() - return + throw 'Skipped: cannot run Vim in a terminal window' endif " Check that v:count is saved and restored, not changed by a timer. call writefile([ @@ -315,7 +316,7 @@ endfunc " Test that the garbage collector isn't triggered if a timer callback invokes " vgetc(). -func Test_nocatch_garbage_collect() +func Test_timer_nocatch_garbage_collect() " skipped: Nvim does not support test_garbagecollect_soon(), test_override() return " 'uptimetime. must be bigger than the timer timeout @@ -339,7 +340,7 @@ func Test_nocatch_garbage_collect() delfunc FeedChar endfunc -func Test_error_in_timer_callback() +func Test_timer_error_in_timer_callback() if !has('terminal') || (has('win32') && has('gui_running')) throw 'Skipped: cannot run Vim in a terminal window' endif -- cgit From 061e573e7ed4fc01c0589018958b3734b4dd3bcf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Jul 2022 10:17:42 +0800 Subject: vim-patch:8.1.1859: timer test sometimes fails on Mac Problem: Timer test sometimes fails on Mac. Solution: Show more info when it fails. https://github.com/vim/vim/commit/427dddf014fea1326ea7f8c0951b0667dc037409 --- src/nvim/testdir/test_timers.vim | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index f5e988e4d1..22a1587152 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -158,6 +158,7 @@ func StopTimer2(timer) endfunc func Test_timer_stop_in_callback() + call assert_equal(0, len(timer_info())) let g:timer1 = timer_start(10, 'StopTimer1') sleep 40m call assert_equal(0, len(timer_info())) @@ -168,16 +169,18 @@ func StopTimerAll(timer) endfunc func Test_timer_stop_all_in_callback() - call timer_stopall() - let g:timer1 = timer_start(10, 'StopTimerAll') - let info = timer_info() - call assert_equal(1, len(info)) - if has('mac') - sleep 100m - endif - sleep 40m - let info = timer_info() - call assert_equal(0, len(info)) + call assert_equal(0, len(timer_info())) + call timer_start(10, 'StopTimerAll') + call assert_equal(1, len(timer_info())) + let slept = 0 + for i in range(10) + if len(timer_info()) == 0 + break + endif + sleep 10m + let slept += 10 + endfor + call assert_inrange(0, 30, slept) endfunc func FeedkeysCb(timer) -- cgit From 5119d10d41efd5250e4798c78571a73a478c473f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Jul 2022 10:20:47 +0800 Subject: vim-patch:8.1.1864: still a timer test that is flaky on Mac Problem: Still a timer test that is flaky on Mac. Solution: Adjust the sleep times. https://github.com/vim/vim/commit/413c04e8d515f604a17b90295c86a0fd547518ba --- src/nvim/testdir/test_timers.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 22a1587152..eea27e4b90 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -150,7 +150,7 @@ func StopTimer1(timer) let g:timer2 = 10->timer_start('StopTimer2') " avoid maxfuncdepth error call timer_pause(g:timer1, 1) - sleep 40m + sleep 20m endfunc func StopTimer2(timer) @@ -160,7 +160,7 @@ endfunc func Test_timer_stop_in_callback() call assert_equal(0, len(timer_info())) let g:timer1 = timer_start(10, 'StopTimer1') - sleep 40m + sleep 50m call assert_equal(0, len(timer_info())) endfunc -- cgit From d8f64267141ec560cf712497f953b2057b708b31 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Jul 2022 10:21:27 +0800 Subject: vim-patch:8.1.1867: still a timer test that is flaky on Mac Problem: Still a timer test that is flaky on Mac. Solution: Loop with a sleep instead of one fixed sleep. https://github.com/vim/vim/commit/315244d85b9b8faae549b1700e8cc2e45eaa68ea --- src/nvim/testdir/test_timers.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index eea27e4b90..3dd97c8081 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -160,8 +160,16 @@ endfunc func Test_timer_stop_in_callback() call assert_equal(0, len(timer_info())) let g:timer1 = timer_start(10, 'StopTimer1') - sleep 50m - call assert_equal(0, len(timer_info())) + let slept = 0 + for i in range(10) + if len(timer_info()) == 0 + break + endif + sleep 10m + let slept += 10 + endfor + " This should take only 30 msec, but on Mac it's often longer + call assert_inrange(0, 50, slept) endfunc func StopTimerAll(timer) -- cgit From cea96ca39d7fabccd50f7855e52de0a66874e743 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 12 Jul 2022 06:55:32 +0800 Subject: test(old): test_timers.vim call timer_stopall() in SetUp() instead --- src/nvim/testdir/test_timers.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 3dd97c8081..a36d65a8dd 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -7,6 +7,10 @@ source shared.vim source term_util.vim source load.vim +func SetUp() + call timer_stopall() +endfunc + func MyHandler(timer) let g:val += 1 endfunc @@ -40,7 +44,6 @@ func Test_timer_repeat_three() endfunc func Test_timer_repeat_many() - call timer_stopall() let g:val = 0 let timer = timer_start(50, 'MyHandler', {'repeat': -1}) if has('mac') @@ -94,7 +97,6 @@ func Test_timer_info() endfunc func Test_timer_stopall() - call timer_stopall() let id1 = timer_start(1000, 'MyHandler') let id2 = timer_start(2000, 'MyHandler') let info = timer_info() -- cgit