[PATCH 4/6] test: make vinyl/replica_rejoin more stable

Vladimir Davydov vdavydov.dev at gmail.com
Sun Jun 30 22:40:17 MSK 2019


The test checks that files left after rebootstrap are removed by the
garbage collector. It does that by printing file names to the result
file. This is inherently unstable, because should timing change, and
we can easily get an extra dump or compaction resulting in a different
set of files and hence test failure. Let's rewrite the test so that
it checks that files are actually removed using fio.path.exists().
---
 test/vinyl/replica_rejoin.result   | 119 ++++++++++++++++++-------------------
 test/vinyl/replica_rejoin.test.lua |  34 ++++++-----
 2 files changed, 79 insertions(+), 74 deletions(-)

diff --git a/test/vinyl/replica_rejoin.result b/test/vinyl/replica_rejoin.result
index 1dfcb91b..6e8156fe 100644
--- a/test/vinyl/replica_rejoin.result
+++ b/test/vinyl/replica_rejoin.result
@@ -11,6 +11,12 @@ test_run = env.new()
 box.schema.user.grant('guest', 'replication')
 ---
 ...
+_ = box.schema.space.create('mem')
+---
+...
+_ = box.space.mem:create_index('pk', {parts = {1, 'string'}})
+---
+...
 _ = box.schema.space.create('test', { id = 9000, engine = 'vinyl' })
 ---
 ...
@@ -36,28 +42,12 @@ test_run:cmd("start server replica")
 ---
 - true
 ...
-test_run:cmd("switch replica")
+files = test_run:eval("replica", "fio = require('fio') return fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*'))")[1]
 ---
-- true
 ...
-fio = require('fio')
+_ = box.space.mem:replace{'files', files}
 ---
 ...
-fio.chdir(box.cfg.vinyl_dir)
----
-- true
-...
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
----
-- - 9000/0/00000000000000000002.index
-  - 9000/0/00000000000000000002.run
-  - 9000/0/00000000000000000004.index
-  - 9000/0/00000000000000000004.run
-...
-test_run:cmd("switch default")
----
-- true
-...
 test_run:cmd("stop server replica")
 ---
 - true
@@ -97,20 +87,6 @@ box.snapshot()
 ---
 - ok
 ...
-fio = require('fio')
----
-...
-fio.chdir(box.cfg.vinyl_dir)
----
-- true
-...
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
----
-- - 9000/0/00000000000000000008.index
-  - 9000/0/00000000000000000008.run
-  - 9000/0/00000000000000000010.index
-  - 9000/0/00000000000000000010.run
-...
 box.space.test:count() -- 99
 ---
 - 99
@@ -119,6 +95,28 @@ test_run:cmd("switch default")
 ---
 - true
 ...
+files = box.space.mem:get('files')[2]
+---
+...
+ok = true
+---
+...
+fio = require('fio')
+---
+...
+for _, f in ipairs(files) do ok = ok and not fio.path.exists(f) end
+---
+...
+ok
+---
+- true
+...
+files = test_run:eval("replica", "fio = require('fio') return fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*'))")[1]
+---
+...
+_ = box.space.mem:replace{'files', files}
+---
+...
 test_run:cmd("stop server replica")
 ---
 - true
@@ -164,20 +162,6 @@ test_run:cmd("switch replica")
 ---
 - true
 ...
-fio = require('fio')
----
-...
-fio.chdir(box.cfg.vinyl_dir)
----
-- true
-...
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
----
-- - 9000/0/00000000000000000008.index
-  - 9000/0/00000000000000000008.run
-  - 9000/0/00000000000000000010.index
-  - 9000/0/00000000000000000010.run
-...
 box.space.test:count() -- 99
 ---
 - 99
@@ -186,6 +170,16 @@ test_run:cmd("switch default")
 ---
 - true
 ...
+old_files = box.space.mem:get('files')[2]
+---
+...
+new_files = test_run:eval("replica", "fio = require('fio') return fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*'))")[1]
+---
+...
+#old_files == #new_files
+---
+- true
+...
 test_run:cmd("stop server replica")
 ---
 - true
@@ -211,20 +205,6 @@ box.snapshot()
 ---
 - ok
 ...
-fio = require('fio')
----
-...
-fio.chdir(box.cfg.vinyl_dir)
----
-- true
-...
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
----
-- - 9000/0/00000000000000000022.index
-  - 9000/0/00000000000000000022.run
-  - 9000/0/00000000000000000024.index
-  - 9000/0/00000000000000000024.run
-...
 box.space.test:count() -- 98
 ---
 - 98
@@ -233,6 +213,22 @@ test_run:cmd("switch default")
 ---
 - true
 ...
+files = box.space.mem:get('files')[2]
+---
+...
+ok = true
+---
+...
+fio = require('fio')
+---
+...
+for _, f in ipairs(files) do ok = ok and not fio.path.exists(f) end
+---
+...
+ok
+---
+- true
+...
 test_run:cmd("stop server replica")
 ---
 - true
@@ -245,6 +241,9 @@ test_run:cmd("cleanup server replica")
 box.space.test:drop()
 ---
 ...
+box.space.mem:drop()
+---
+...
 box.schema.user.revoke('guest', 'replication')
 ---
 ...
diff --git a/test/vinyl/replica_rejoin.test.lua b/test/vinyl/replica_rejoin.test.lua
index 2c5a69e0..cbb17ef2 100644
--- a/test/vinyl/replica_rejoin.test.lua
+++ b/test/vinyl/replica_rejoin.test.lua
@@ -6,6 +6,8 @@ test_run = env.new()
 -- after rebootstrap.
 --
 box.schema.user.grant('guest', 'replication')
+_ = box.schema.space.create('mem')
+_ = box.space.mem:create_index('pk', {parts = {1, 'string'}})
 _ = box.schema.space.create('test', { id = 9000, engine = 'vinyl' })
 _ = box.space.test:create_index('pk')
 pad = string.rep('x', 12 * 1024)
@@ -15,11 +17,8 @@ box.snapshot()
 -- Join a replica. Check its files.
 test_run:cmd("create server replica with rpl_master=default, script='vinyl/replica_rejoin.lua'")
 test_run:cmd("start server replica")
-test_run:cmd("switch replica")
-fio = require('fio')
-fio.chdir(box.cfg.vinyl_dir)
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
-test_run:cmd("switch default")
+files = test_run:eval("replica", "fio = require('fio') return fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*'))")[1]
+_ = box.space.mem:replace{'files', files}
 test_run:cmd("stop server replica")
 
 -- Invoke garbage collector on the master.
@@ -36,11 +35,15 @@ test_run:cmd("start server replica")
 test_run:cmd("switch replica")
 box.cfg{checkpoint_count = 1}
 box.snapshot()
-fio = require('fio')
-fio.chdir(box.cfg.vinyl_dir)
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
 box.space.test:count() -- 99
 test_run:cmd("switch default")
+files = box.space.mem:get('files')[2]
+ok = true
+fio = require('fio')
+for _, f in ipairs(files) do ok = ok and not fio.path.exists(f) end
+ok
+files = test_run:eval("replica", "fio = require('fio') return fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*'))")[1]
+_ = box.space.mem:replace{'files', files}
 test_run:cmd("stop server replica")
 
 -- Invoke garbage collector on the master.
@@ -59,11 +62,11 @@ test_run:cmd("start server replica with crash_expected=True") -- fail
 test_run:cmd("start server replica with crash_expected=True") -- fail again
 test_run:cmd("start server replica with args='disable_replication'")
 test_run:cmd("switch replica")
-fio = require('fio')
-fio.chdir(box.cfg.vinyl_dir)
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
 box.space.test:count() -- 99
 test_run:cmd("switch default")
+old_files = box.space.mem:get('files')[2]
+new_files = test_run:eval("replica", "fio = require('fio') return fio.glob(fio.pathjoin(box.cfg.vinyl_dir, box.space.test.id, 0, '*'))")[1]
+#old_files == #new_files
 test_run:cmd("stop server replica")
 box.error.injection.set('ERRINJ_RELAY_FINAL_JOIN', false)
 
@@ -73,14 +76,17 @@ test_run:cmd("start server replica")
 test_run:cmd("switch replica")
 box.cfg{checkpoint_count = 1}
 box.snapshot()
-fio = require('fio')
-fio.chdir(box.cfg.vinyl_dir)
-fio.glob(fio.pathjoin(box.space.test.id, 0, '*'))
 box.space.test:count() -- 98
 test_run:cmd("switch default")
+files = box.space.mem:get('files')[2]
+ok = true
+fio = require('fio')
+for _, f in ipairs(files) do ok = ok and not fio.path.exists(f) end
+ok
 test_run:cmd("stop server replica")
 
 -- Cleanup.
 test_run:cmd("cleanup server replica")
 box.space.test:drop()
+box.space.mem:drop()
 box.schema.user.revoke('guest', 'replication')
-- 
2.11.0




More information about the Tarantool-patches mailing list