fileio_spec.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local command = helpers.command
  4. local eq = helpers.eq
  5. local feed = helpers.feed
  6. local funcs = helpers.funcs
  7. local nvim_prog = helpers.nvim_prog
  8. local request = helpers.request
  9. local retry = helpers.retry
  10. local rmdir = helpers.rmdir
  11. local sleep = helpers.sleep
  12. describe('fileio', function()
  13. before_each(function()
  14. end)
  15. after_each(function()
  16. command(':qall!')
  17. os.remove('Xtest_startup_shada')
  18. os.remove('Xtest_startup_file1')
  19. os.remove('Xtest_startup_file2')
  20. rmdir('Xtest_startup_swapdir')
  21. end)
  22. it('fsync() codepaths #8304', function()
  23. clear({ args={ '-i', 'Xtest_startup_shada',
  24. '--cmd', 'set directory=Xtest_startup_swapdir' } })
  25. -- These cases ALWAYS force fsync (regardless of 'fsync' option):
  26. -- 1. Idle (CursorHold) with modified buffers (+ 'swapfile').
  27. command('write Xtest_startup_file1')
  28. feed('ifoo<esc>h')
  29. command('write')
  30. eq(0, request('nvim__stats').fsync) -- 'nofsync' is the default.
  31. command('set swapfile')
  32. command('set updatetime=1')
  33. feed('izub<esc>h') -- File is 'modified'.
  34. sleep(3) -- Allow 'updatetime' to expire.
  35. retry(3, nil, function()
  36. eq(1, request('nvim__stats').fsync)
  37. end)
  38. command('set updatetime=9999')
  39. -- 2. Exit caused by deadly signal (+ 'swapfile').
  40. local j = funcs.jobstart({ nvim_prog, '-u', 'NONE', '-i',
  41. 'Xtest_startup_shada', '--headless',
  42. '-c', 'set swapfile',
  43. '-c', 'write Xtest_startup_file2',
  44. '-c', 'put =localtime()', })
  45. sleep(10) -- Let Nvim start.
  46. funcs.jobstop(j) -- Send deadly signal.
  47. -- 3. SIGPWR signal.
  48. -- ??
  49. -- 4. Explicit :preserve command.
  50. command('preserve')
  51. eq(2, request('nvim__stats').fsync)
  52. -- 5. Enable 'fsync' option, write file.
  53. command('set fsync')
  54. feed('ibaz<esc>h')
  55. command('write')
  56. eq(4, request('nvim__stats').fsync)
  57. end)
  58. end)