Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergei Voronezhskii <sergw@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	Vladimir Davydov <vdavydov.dev@gmail.com>
Subject: [PATCH 1/2] test: wait until expected value appear in log
Date: Wed, 10 Oct 2018 10:56:26 +0300	[thread overview]
Message-ID: <20181010075627.40822-2-sergw@tarantool.org> (raw)
In-Reply-To: <20181010075627.40822-1-sergw@tarantool.org>

Sleep for the constant time can't fit the case when we need to wait for
snapshot. System load may change app timings and we got flaky test.
Need to check logfile with delay until timeout or log has expected
entry.

Fixes #3684

Part of #2436, #3232
---
 test/xlog/checkpoint_daemon.result   | 22 +++++++++++++++++-----
 test/xlog/checkpoint_daemon.test.lua | 21 ++++++++++++++++-----
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/test/xlog/checkpoint_daemon.result b/test/xlog/checkpoint_daemon.result
index d5ed666f2..e712a0f11 100644
--- a/test/xlog/checkpoint_daemon.result
+++ b/test/xlog/checkpoint_daemon.result
@@ -73,6 +73,21 @@ for i = 1, 100 do
 end;
 ---
 ...
+function wait_cond(fn, timeout, delay)
+    timeout = timeout or 1.0
+    delay = delay or 0.001
+    local t1 = fiber.time()
+    while not fn() do
+        local work_time = fiber.time() - t1
+        if work_time > timeout then
+            return false
+        end
+        fiber.sleep(delay)
+    end
+    return true
+end;
+---
+...
 test_run:cmd("setopt delimiter ''");
 ---
 - true
@@ -90,15 +105,12 @@ fio.basename(snaps[1], '.snap') >= fio.basename(xlogs[1], '.xlog')
 - true
 ...
 -- gh-2780 check that scheduled snapshots are performed
-fiber.sleep(3 * PERIOD)
----
-...
 -- check that it's not first snapshot
-test_run:grep_log("default", "saving snapshot", 400) == nil
+wait_cond(function() return test_run:grep_log("default", "saving snapshot", 400) == nil end)
 ---
 - true
 ...
-test_run:grep_log("default", "making snapshot", 400) ~= nil
+wait_cond(function() return test_run:grep_log("default", "making snapshot", 400) ~= nil end)
 ---
 - true
 ...
diff --git a/test/xlog/checkpoint_daemon.test.lua b/test/xlog/checkpoint_daemon.test.lua
index 4a0aafa84..02f2768d9 100644
--- a/test/xlog/checkpoint_daemon.test.lua
+++ b/test/xlog/checkpoint_daemon.test.lua
@@ -44,9 +44,21 @@ for i = 1, 100 do
     end
 end;
 
-test_run:cmd("setopt delimiter ''");
-
+function wait_cond(fn, timeout, delay)
+    timeout = timeout or 1.0
+    delay = delay or 0.001
+    local t1 = fiber.time()
+    while not fn() do
+        local work_time = fiber.time() - t1
+        if work_time > timeout then
+            return false
+        end
+        fiber.sleep(delay)
+    end
+    return true
+end;
 
+test_run:cmd("setopt delimiter ''");
 
 #snaps == 2 or snaps
 #xlogs > 0
@@ -54,10 +66,9 @@ test_run:cmd("setopt delimiter ''");
 fio.basename(snaps[1], '.snap') >= fio.basename(xlogs[1], '.xlog')
 
 -- gh-2780 check that scheduled snapshots are performed
-fiber.sleep(3 * PERIOD)
 -- check that it's not first snapshot
-test_run:grep_log("default", "saving snapshot", 400) == nil
-test_run:grep_log("default", "making snapshot", 400) ~= nil
+wait_cond(function() return test_run:grep_log("default", "saving snapshot", 400) == nil end)
+wait_cond(function() return test_run:grep_log("default", "making snapshot", 400) ~= nil end)
 
 -- restore default options
 box.cfg{checkpoint_interval = 3600 * 4, checkpoint_count = 4 }
-- 
2.18.0

  reply	other threads:[~2018-10-10  7:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10  7:56 [PATCH] test: enable parallel mode for xlog tests Sergei Voronezhskii
2018-10-10  7:56 ` Sergei Voronezhskii [this message]
2018-10-15  0:29   ` [PATCH 1/2] test: wait until expected value appear in log Alexander Turenko
2018-10-17 22:04     ` [PATCH] test: enable parallel mode for xlog tests Sergei Voronezhskii
2018-10-17 22:04       ` [PATCH 1/2] test: wait until expected value appear in log Sergei Voronezhskii
2018-10-21  4:40         ` Alexander Turenko
2018-10-23 15:00           ` Re[2]: " Sergei Voronezhskii
2018-10-25  2:49             ` Alexander Turenko
2018-10-17 22:04       ` [PATCH 2/2] test: enable parallel mode for xlog tests Sergei Voronezhskii
2018-11-27 13:33         ` [tarantool-patches] " Sergei Voronezhskii
2018-11-28 14:42       ` [tarantool-patches] [PATCH] " Kirill Yukhin
2018-10-10  7:56 ` [PATCH 2/2] " Sergei Voronezhskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181010075627.40822-2-sergw@tarantool.org \
    --to=sergw@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH 1/2] test: wait until expected value appear in log' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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