Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH] test: fix vinyl/errinj_stat failure
@ 2019-04-10 13:52 Vladimir Davydov
  2019-04-10 13:53 ` Vladimir Davydov
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Davydov @ 2019-04-10 13:52 UTC (permalink / raw)
  To: tarantool-patches

The patch fixes the following test failures:

 | [022] --- vinyl/errinj_stat.result	Tue Mar 19 17:52:48 2019
 | [022] +++ vinyl/errinj_stat.reject	Wed Mar 20 08:08:41 2019
 | [022] @@ -229,7 +229,7 @@
 | [022] ...
 | [022] stat.tasks_inprogress == 0
 | [022] ---
 | [022] -- true
 | [022] +- false
 | [022] ...
 | [022] stat.tasks_completed == 1
 | [022] ---

 | [013] --- vinyl/errinj_stat.result	Tue Mar 19 17:52:48 2019
 | [013] +++ vinyl/errinj_stat.reject	Wed Mar 20 08:11:15 2019
 | [013] @@ -168,7 +168,7 @@
 | [013] ...
 | [013] stat.tasks_inprogress > 0
 | [013] ---
 | [013] -- true
 | [013] +- false
 | [013] ...
 | [013] stat.tasks_completed == 0
 | [013] ---
 | [013] @@ -183,7 +183,7 @@
 | [013] ...
 | [013] box.stat.vinyl().scheduler.tasks_inprogress > 0
 | [013] ---
 | [013] -- true
 | [013] +- false
 | [013] ...
 | [013] errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', false)
 | [013] ---

The problem occurred, because the test didn't make sure that an
asynchronous dump/compaction task has actually started/completed.
Even box.snapshot() doesn't guarantee that a dump task is complete,
in fact. This patch adds wait_cond's to guarantee the test never
fails like that anymore.

Closes #4059
Closes #4060
---
 test/vinyl/errinj_stat.result   | 52 +++++++++++++++++++++++++++++------------
 test/vinyl/errinj_stat.test.lua | 25 ++++++++++++--------
 2 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/test/vinyl/errinj_stat.result b/test/vinyl/errinj_stat.result
index 08801dbc..a4e63357 100644
--- a/test/vinyl/errinj_stat.result
+++ b/test/vinyl/errinj_stat.result
@@ -143,7 +143,7 @@ box.stat.reset()
 s = box.schema.space.create('test', {engine = 'vinyl'})
 ---
 ...
-_ = s:create_index('pk')
+i = s:create_index('pk')
 ---
 ...
 errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', true)
@@ -154,14 +154,12 @@ s:replace{1}
 ---
 - [1]
 ...
-c = fiber.channel(1)
+_ = fiber.create(function() box.snapshot() end)
 ---
 ...
-_ = fiber.create(function() box.snapshot() c:put(true) end)
----
-...
-fiber.sleep(0.01)
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_inprogress > 0 end)
 ---
+- true
 ...
 stat = box.stat.vinyl().scheduler
 ---
@@ -189,7 +187,7 @@ errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', false)
 ---
 - ok
 ...
-c:get()
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_completed > 0 end)
 ---
 - true
 ...
@@ -227,10 +225,6 @@ box.snapshot()
 stat = box.stat.vinyl().scheduler
 ---
 ...
-stat.tasks_inprogress == 0
----
-- true
-...
 stat.tasks_completed == 1
 ---
 - true
@@ -250,6 +244,28 @@ errinj.set('ERRINJ_VY_SCHED_TIMEOUT', 0)
 fiber.sleep(0.01)
 ---
 ...
+box.snapshot()
+---
+- ok
+...
+i:compact()
+---
+...
+test_run:wait_cond(function() return i:stat().disk.compaction.count > 0 end)
+---
+- true
+...
+stat = box.stat.vinyl().scheduler
+---
+...
+stat.tasks_inprogress == 0
+---
+- true
+...
+stat.tasks_completed == 3
+---
+- true
+...
 s:drop()
 ---
 ...
@@ -291,11 +307,12 @@ errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', true)
 start_time = fiber.time()
 ---
 ...
-c = fiber.channel(1)
+_ = fiber.create(function() box.snapshot() end)
 ---
 ...
-_ = fiber.create(function() box.snapshot() c:put(true) end)
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_inprogress > 0 end)
 ---
+- true
 ...
 fiber.sleep(0.1)
 ---
@@ -304,7 +321,7 @@ errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', false)
 ---
 - ok
 ...
-c:get()
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_completed > 0 end)
 ---
 - true
 ...
@@ -345,6 +362,10 @@ start_time = fiber.time()
 i:compact()
 ---
 ...
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_inprogress > 0 end)
+---
+- true
+...
 fiber.sleep(0.1)
 ---
 ...
@@ -352,8 +373,9 @@ errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', false)
 ---
 - ok
 ...
-while i:stat().disk.compaction.count == 0 do fiber.sleep(0.01) end
+test_run:wait_cond(function() return i:stat().disk.compaction.time > 0 end)
 ---
+- true
 ...
 i:stat().disk.compaction.time >= 0.1
 ---
diff --git a/test/vinyl/errinj_stat.test.lua b/test/vinyl/errinj_stat.test.lua
index 19f3d119..c3000bba 100644
--- a/test/vinyl/errinj_stat.test.lua
+++ b/test/vinyl/errinj_stat.test.lua
@@ -47,12 +47,11 @@ s:drop()
 --
 box.stat.reset()
 s = box.schema.space.create('test', {engine = 'vinyl'})
-_ = s:create_index('pk')
+i = s:create_index('pk')
 errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', true)
 s:replace{1}
-c = fiber.channel(1)
-_ = fiber.create(function() box.snapshot() c:put(true) end)
-fiber.sleep(0.01)
+_ = fiber.create(function() box.snapshot() end)
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_inprogress > 0 end)
 stat = box.stat.vinyl().scheduler
 stat.tasks_inprogress > 0
 stat.tasks_completed == 0
@@ -60,7 +59,7 @@ stat.tasks_failed == 0
 box.stat.reset() -- doesn't affect tasks_inprogress
 box.stat.vinyl().scheduler.tasks_inprogress > 0
 errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', false)
-c:get()
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_completed > 0 end)
 stat = box.stat.vinyl().scheduler
 stat.tasks_inprogress == 0
 stat.tasks_completed == 1
@@ -70,12 +69,17 @@ errinj.set('ERRINJ_VY_SCHED_TIMEOUT', 0.01)
 s:replace{2}
 box.snapshot()
 stat = box.stat.vinyl().scheduler
-stat.tasks_inprogress == 0
 stat.tasks_completed == 1
 stat.tasks_failed > 0
 errinj.set('ERRINJ_VY_RUN_WRITE', false)
 errinj.set('ERRINJ_VY_SCHED_TIMEOUT', 0)
 fiber.sleep(0.01)
+box.snapshot()
+i:compact()
+test_run:wait_cond(function() return i:stat().disk.compaction.count > 0 end)
+stat = box.stat.vinyl().scheduler
+stat.tasks_inprogress == 0
+stat.tasks_completed == 3
 s:drop()
 
 --
@@ -92,11 +96,11 @@ box.stat.vinyl().scheduler.compaction_time == 0
 for i = 1, 100 do s:replace{i} end
 errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', true)
 start_time = fiber.time()
-c = fiber.channel(1)
-_ = fiber.create(function() box.snapshot() c:put(true) end)
+_ = fiber.create(function() box.snapshot() end)
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_inprogress > 0 end)
 fiber.sleep(0.1)
 errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', false)
-c:get()
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_completed > 0 end)
 i:stat().disk.dump.time >= 0.1
 i:stat().disk.dump.time <= fiber.time() - start_time
 i:stat().disk.compaction.time == 0
@@ -108,9 +112,10 @@ box.snapshot()
 errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', true)
 start_time = fiber.time()
 i:compact()
+test_run:wait_cond(function() return box.stat.vinyl().scheduler.tasks_inprogress > 0 end)
 fiber.sleep(0.1)
 errinj.set('ERRINJ_VY_RUN_WRITE_DELAY', false)
-while i:stat().disk.compaction.count == 0 do fiber.sleep(0.01) end
+test_run:wait_cond(function() return i:stat().disk.compaction.time > 0 end)
 i:stat().disk.compaction.time >= 0.1
 i:stat().disk.compaction.time <= fiber.time() - start_time
 box.stat.vinyl().scheduler.compaction_time == i:stat().disk.compaction.time
-- 
2.11.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-10 13:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10 13:52 [PATCH] test: fix vinyl/errinj_stat failure Vladimir Davydov
2019-04-10 13:53 ` Vladimir Davydov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox