test: 'nofsync' with deadly signal #26415

Problem:
The test for 'nofsync' swapfile preservation on a deadly signal, does
not actually assert anything.

followup to 1fd29a2884

Solution:
Check that swapfile contents are present after getting SIGTERM.
TODO: this doesn't really verify that 'fsync' was called; it still
passes with this patch:

    diff --git a/src/nvim/main.c b/src/nvim/main.c
    index 216e39f3e81c..7a635520401d 100644
    --- a/src/nvim/main.c
    +++ b/src/nvim/main.c
    @@ -838,7 +838,7 @@ void preserve_exit(const char *errmsg)
           if (errmsg != NULL) {
             os_errmsg("Vim: preserving files...\r\n");
           }
    -      ml_sync_all(false, false, true);  // preserve all swap files
    +      ml_sync_all(false, false, false);  // preserve all swap files
           break;
         }
       }

However it correctly fails with this patch, at least:

    diff --git a/src/nvim/main.c b/src/nvim/main.c
    index 216e39f3e81c..f2306c310ddc 100644
    --- a/src/nvim/main.c
    +++ b/src/nvim/main.c
    @@ -838,7 +838,6 @@ void preserve_exit(const char *errmsg)
           if (errmsg != NULL) {
             os_errmsg("Vim: preserving files...\r\n");
           }
    -      ml_sync_all(false, false, true);  // preserve all swap files
           break;
         }
       }
This commit is contained in:
Justin M. Keyes 2023-12-06 07:11:36 -08:00 committed by GitHub
parent f64e4b43e1
commit c84af395e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 10 deletions

View File

@ -30,6 +30,8 @@ local feed_command = helpers.feed_command
local skip = helpers.skip
local is_os = helpers.is_os
local is_ci = helpers.is_ci
local spawn = helpers.spawn
local set_session = helpers.set_session
describe('fileio', function()
before_each(function()
@ -49,6 +51,23 @@ describe('fileio', function()
rmdir('Xtest_backupdir with spaces')
end)
local args = { nvim_prog, '--clean', '--cmd', 'set nofsync directory=Xtest_startup_swapdir', }
--- Starts a new nvim session and returns an attached screen.
local function startup(extra_args)
extra_args = extra_args or {}
local argv = vim.tbl_flatten({args, '--embed', extra_args})
local screen_nvim = spawn(argv)
set_session(screen_nvim)
local screen = Screen.new(70, 10)
screen:attach()
screen:set_default_attr_ids({
[1] = {foreground = Screen.colors.NvimDarkGrey4};
[2] = {background = Screen.colors.NvimDarkGrey1, foreground = Screen.colors.NvimLightGrey3};
[3] = {foreground = Screen.colors.NvimLightCyan};
})
return screen
end
it("fsync() with 'nofsync' #8304", function()
clear({ args={ '--cmd', 'set nofsync directory=Xtest_startup_swapdir', } })
@ -81,16 +100,24 @@ describe('fileio', function()
eq('foozubbaz', trim(read_file('Xtest_startup_file1')))
-- 4. Exit caused by deadly signal (+ 'swapfile').
local j = funcs.jobstart({ nvim_prog, '-u', 'NONE', '--headless',
'--cmd', 'set nofsync directory=Xtest_startup_swapdir',
'-c', 'set swapfile',
'-c', 'write Xtest_startup_file2',
'-c', 'put =localtime()', })
sleep(10) -- Let Nvim start.
local j = funcs.jobstart(vim.tbl_flatten({args, '--embed'}), {rpc=true})
funcs.rpcrequest(j, 'nvim_exec2', [[
set nofsync directory=Xtest_startup_swapdir
edit Xtest_startup_file2
write
put ='fsyncd text'
]], {})
eq('Xtest_startup_swapdir', funcs.rpcrequest(j, 'nvim_eval', '&directory'))
funcs.jobstop(j) -- Send deadly signal.
local screen = startup()
feed(':recover Xtest_startup_file2<cr>')
screen:expect({any = [[Using swap file "Xtest_startup_swapdir[/\]Xtest_startup_file2%.swp"]]})
feed('<cr>')
screen:expect({any = 'fsyncd text'})
-- 5. SIGPWR signal.
-- ??
-- oldtest: Test_signal_PWR()
end)
it('backup #9709', function()

View File

@ -438,7 +438,7 @@ function module.connect(file_or_address)
return Session.new(stream)
end
-- Starts a new global Nvim session.
-- Starts (and returns) a new global Nvim session.
--
-- Parameters are interpreted as startup args, OR a map with these keys:
-- args: List: Args appended to the default `nvim_argv` set.
@ -452,6 +452,7 @@ end
-- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}}
function module.clear(...)
module.set_session(module.spawn_argv(false, ...))
return module.get_session()
end
-- same params as clear, but does returns the session instead
@ -943,7 +944,7 @@ function module.add_builddir_to_rtp()
module.command(string.format([[set rtp+=%s/runtime]], module.test_build_dir))
end
-- Kill process with given pid
-- Kill (reap) a process by PID.
function module.os_kill(pid)
return os.execute((is_os('win')
and 'taskkill /f /t /pid '..pid..' > nul'

View File

@ -12,7 +12,7 @@ describe('screen', function()
helpers.nvim_prog,
'-u', 'NONE',
'-i', 'NONE',
'-N',
'-n',
'--cmd', 'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler',
'--cmd', 'colorscheme vim',
'--embed',