diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-04-24 00:27:09 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-04-24 00:44:06 +0200 |
commit | 77cb14cc6da5dff685c6e5a4005da433c39d5ff7 (patch) | |
tree | 4c3af7879d5cbef319e7df61c4c336eb1e0acee8 | |
parent | 32f3937477e05b13e05bba4463c5cfd417a2fde8 (diff) | |
download | rneovim-77cb14cc6da5dff685c6e5a4005da433c39d5ff7.tar.gz rneovim-77cb14cc6da5dff685c6e5a4005da433c39d5ff7.tar.bz2 rneovim-77cb14cc6da5dff685c6e5a4005da433c39d5ff7.zip |
API: nvim__stats()
Use it to verify fsync() behavior.
-rw-r--r-- | src/nvim/api/vim.c | 11 | ||||
-rw-r--r-- | src/nvim/globals.h | 5 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 1 | ||||
-rw-r--r-- | test/functional/core/fileio_spec.lua | 21 |
4 files changed, 31 insertions, 7 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 07ec6e8c27..64fe1359c6 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1473,6 +1473,17 @@ Float nvim__id_float(Float flt) return flt; } +/// Gets internal stats. +/// +/// @return Map of various internal stats. +Dictionary nvim__stats(void) +{ + Dictionary rv = ARRAY_DICT_INIT; + PUT(rv, "fsync", INTEGER_OBJ(g_stats.fsync)); + PUT(rv, "redraw", INTEGER_OBJ(g_stats.redraw)); + return rv; +} + /// Gets a list of dictionaries representing attached UIs. /// /// @return Array of UI dictionaries diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 56790bc89b..403a5928c9 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -80,6 +80,11 @@ typedef enum { kTrue = 1, } TriState; +EXTERN struct nvim_stats_s { + int64_t fsync; + int64_t redraw; +} g_stats INIT(= { 0, 0 }); + /* Values for "starting" */ #define NO_SCREEN 2 /* no screen updating yet */ #define NO_BUFFERS 1 /* not all buffers loaded yet */ diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 0414794d01..3e1af7f1c2 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -629,6 +629,7 @@ int os_fsync(int fd) { int r; RUN_UV_FS_FUNC(r, uv_fs_fsync, fd, NULL); + g_stats.fsync++; return r; } diff --git a/test/functional/core/fileio_spec.lua b/test/functional/core/fileio_spec.lua index 848ef7cae0..09533e4e60 100644 --- a/test/functional/core/fileio_spec.lua +++ b/test/functional/core/fileio_spec.lua @@ -3,10 +3,11 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local eval = helpers.eval local feed = helpers.feed local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog +local request = helpers.request +local retry = helpers.retry local rmdir = helpers.rmdir local sleep = helpers.sleep @@ -22,20 +23,24 @@ describe('fileio', function() end) it('fsync() codepaths #8304', function() - -- This is an "acceptance test" or "smoke test". - clear({ args={ '-i', 'Xtest_startup_shada', '--cmd', 'set directory=Xtest_startup_swapdir' } }) -- These cases ALWAYS force fsync (regardless of 'fsync' option): -- 1. Idle (CursorHold) with modified buffers (+ 'swapfile'). - command('set swapfile') - command('set updatetime=1') command('write Xtest_startup_file1') feed('ifoo<esc>h') - sleep(2) - eq(1, eval('&modified')) + command('write') + eq(0, request('nvim__stats').fsync) -- 'nofsync' is the default. + command('set swapfile') + command('set updatetime=1') + feed('izub<esc>h') -- File is 'modified'. + sleep(3) -- Allow 'updatetime' to expire. + retry(3, nil, function() + eq(1, request('nvim__stats').fsync) + end) + command('set updatetime=9999') -- 2. Exit caused by deadly signal (+ 'swapfile'). local j = funcs.jobstart({ nvim_prog, '-u', 'NONE', '-i', @@ -51,11 +56,13 @@ describe('fileio', function() -- 4. Explicit :preserve command. command('preserve') + eq(2, request('nvim__stats').fsync) -- 5. Enable 'fsync' option, write file. command('set fsync') feed('ibaz<esc>h') command('write') + eq(4, request('nvim__stats').fsync) end) end) |