Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH] test: fix app/socket sporadic failure
Date: Thu, 28 Feb 2019 18:09:41 +0300	[thread overview]
Message-ID: <216e0b14c8981ddbd110d2b4d9562194acdc7860.1551366539.git.vdavydov.dev@gmail.com> (raw)

The patch fixes the following test failure:

 | --- app/socket.result	Mon Feb 25 17:32:49 2019
 | +++ app/socket.reject	Mon Feb 25 17:39:51 2019
 | @@ -2827,7 +2827,7 @@
 |  ...
 |  echo_fiber ~= nil
 |  ---
 | -- true
 | +- false
 |  ...
 |  client:write('hello')
 |  ---

This happens, because we don't wait for echo_fiber to start.
Use a channel to make sure it does. Also, increase read/write
timeouts from 0.1 up to 5 seconds - it won't increase the test
runtime, but it will make it more robust.

Closes #4022
---
https://github.com/tarantool/tarantool/issues/4022
https://github.com/tarantool/tarantool/commits/dv/test-fixes

 test/app/socket.result   | 12 +++++++++---
 test/app/socket.test.lua |  9 ++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/test/app/socket.result b/test/app/socket.result
index 4c92f157..0d029039 100644
--- a/test/app/socket.result
+++ b/test/app/socket.result
@@ -2804,8 +2804,10 @@ test_run:cmd("setopt delimiter ';'")
 - true
 ...
 echo_fiber = nil
+channel = fiber.channel()
 server = socket.tcp_server('localhost', 0, { handler = function(s)
     echo_fiber = fiber.self()
+    channel:put(true)
     while true do
         local b = s:read(1, 0.1)
         if b ~= nil then
@@ -2825,6 +2827,10 @@ addr = server:name()
 client = socket.tcp_connect(addr.host, addr.port)
 ---
 ...
+channel:get()
+---
+- true
+...
 echo_fiber ~= nil
 ---
 - true
@@ -2833,7 +2839,7 @@ client:write('hello')
 ---
 - 5
 ...
-client:read(5, 0.1) == 'hello'
+client:read(5, 5) == 'hello'
 ---
 - true
 ...
@@ -2848,7 +2854,7 @@ client:write('world')
 ---
 - 5
 ...
-client:read(5, 0.1) == 'world'
+client:read(5, 5) == 'world'
 ---
 - true
 ...
@@ -2856,7 +2862,7 @@ client:read(5, 0.1) == 'world'
 fiber.cancel(echo_fiber)
 ---
 ...
-client:read(1, 0.1) == ''
+client:read(1, 5) == ''
 ---
 - true
 ...
diff --git a/test/app/socket.test.lua b/test/app/socket.test.lua
index 462eacf4..dab168f9 100644
--- a/test/app/socket.test.lua
+++ b/test/app/socket.test.lua
@@ -954,8 +954,10 @@ listening_socket:close()
 --gh-3344 connection should not fail is there is a spurious wakeup for io fiber
 test_run:cmd("setopt delimiter ';'")
 echo_fiber = nil
+channel = fiber.channel()
 server = socket.tcp_server('localhost', 0, { handler = function(s)
     echo_fiber = fiber.self()
+    channel:put(true)
     while true do
         local b = s:read(1, 0.1)
         if b ~= nil then
@@ -966,17 +968,18 @@ end, name = 'echoserv'});
 test_run:cmd("setopt delimiter ''");
 addr = server:name()
 client = socket.tcp_connect(addr.host, addr.port)
+channel:get()
 echo_fiber ~= nil
 client:write('hello')
-client:read(5, 0.1) == 'hello'
+client:read(5, 5) == 'hello'
 -- send spurious wakeup
 fiber.wakeup(echo_fiber)
 fiber.sleep(0)
 client:write('world')
-client:read(5, 0.1) == 'world'
+client:read(5, 5) == 'world'
 -- cancel fiber
 fiber.cancel(echo_fiber)
-client:read(1, 0.1) == ''
+client:read(1, 5) == ''
 server:close()
 
 test_run:cmd("clear filter")
-- 
2.11.0

             reply	other threads:[~2019-02-28 15:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28 15:09 Vladimir Davydov [this message]
2019-02-28 15:31 ` Vladimir Davydov

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=216e0b14c8981ddbd110d2b4d9562194acdc7860.1551366539.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH] test: fix app/socket sporadic failure' \
    /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