-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Is your feature request about something that is currently impossible or hard to do? Please describe the problem.
When running make test
in an OS with only 1s granularity timestamp, some tests are impossible to pass as the time leaving for timestamp changes is not long enough. For instance:
vim/src/testdir/test_buffer.vim
Lines 550 to 560 in 44c1c04
call writefile(['one'], 'XallocFail5', 'D') | |
if has('unix') | |
edit XallocFail5 | |
" sleep for some time to make sure the timestamp is different | |
sleep 200m | |
call writefile(['two'], 'XallocFail5') | |
set autoread | |
call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0) | |
call assert_fails('checktime', 'E342:') | |
set autoread& | |
bw! |
Sleep for a longer time like 2 seconds will be enough to pass the test.
In the test:
vim/src/testdir/test_diffmode.vim
Line 2097 in 44c1c04
func Test_diff_overlapped_diff_blocks_will_be_merged() |
In those two functions:
vim/src/testdir/test_diffmode.vim
Lines 840 to 855 in 44c1c04
func WriteDiffFiles(buf, list1, list2) | |
call writefile(a:list1, 'Xdifile1') | |
call writefile(a:list2, 'Xdifile2') | |
if a:buf | |
call term_sendkeys(a:buf, ":checktime\<CR>") | |
endif | |
endfunc | |
func WriteDiffFiles3(buf, list1, list2, list3) | |
call writefile(a:list1, 'Xdifile1') | |
call writefile(a:list2, 'Xdifile2') | |
call writefile(a:list3, 'Xdifile3') | |
if a:buf | |
call term_sendkeys(a:buf, ":checktime\<CR>") | |
endif | |
endfunc |
I think some sleep time is needed for timestamp to change before timecheck
. The reason why it's fine I think it's because of the high-precision timestamp on modern OSes.
Describe the solution you'd like
Investigate more tests like the cases above and add a if-else sleep statement like the following:
vim/src/testdir/test_filechanged.vim
Lines 14 to 19 in 44c1c04
" Need to wait until the timestamp would change. | |
if has('nanotime') | |
sleep 10m | |
else | |
sleep 2 | |
endif |
Additional context
Not sure if nanotime
is the condition should be used in this case, currently has(nanotime)
will be 1
when the library on the OS supports s.ST_MTIM_NSEC
:
Lines 3972 to 3995 in 44c1c04
dnl nanoseconds field of struct stat | |
AC_CACHE_CHECK([for nanoseconds field of struct stat], | |
ac_cv_struct_st_mtim_nsec, | |
[ac_save_CPPFLAGS="$CPPFLAGS" | |
ac_cv_struct_st_mtim_nsec=no | |
# st_mtim.tv_nsec -- the usual case | |
# st_mtim._tv_nsec -- Solaris 2.6, if | |
# (defined _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED == 1 | |
# && !defined __EXTENSIONS__) | |
# st_mtim.st__tim.tv_nsec -- UnixWare 2.1.2 | |
# st_mtime_n -- AIX 5.2 and above | |
# st_mtimespec.tv_nsec -- Darwin (Mac OSX) | |
for ac_val in st_mtim.tv_nsec st_mtim._tv_nsec st_mtim.st__tim.tv_nsec st_mtime_n st_mtimespec.tv_nsec; do | |
CPPFLAGS="$ac_save_CPPFLAGS -DST_MTIM_NSEC=$ac_val" | |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h> | |
#include <sys/stat.h>], [struct stat s; s.ST_MTIM_NSEC;])], | |
[ac_cv_struct_st_mtim_nsec=$ac_val; break]) | |
done | |
CPPFLAGS="$ac_save_CPPFLAGS" | |
]) | |
if test $ac_cv_struct_st_mtim_nsec != no; then | |
AC_DEFINE_UNQUOTED([ST_MTIM_NSEC], [$ac_cv_struct_st_mtim_nsec], | |
[Define if struct stat contains a nanoseconds field]) | |
fi |
However, it's possible that the library indeed supports s.ST_MTIM_NSEC
but the filesystem driver it uses does not support sub-second timestamp, like ext2
without the extended timestamp. Therefore, something like --disable-nanotime
in ./configure
may be useful.
Not sure if the vim maintainers are willing to support this feature, but I can open a PR and work on this if desired :).