From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 5/5] swim: allow to set codec before cfg
Date: Wed, 22 May 2019 22:52:21 +0300 [thread overview]
Message-ID: <e074202e0c7f785a780eb0f71d7e375a3d00803f.1558554655.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1558554655.git.v.shpilevoy@tarantool.org>
One another problem discovered with UDP broadcast test is that
it can affect other tests, even after termination. Doing
swim:broadcast() on one test a programmer can't be sure, who will
listen it, answer, and break the test scenario.
This commit reduces probability of such a problem by
* allowance to set a codec before swim:cfg(). It allows to
protect SWIM nodes of different tests from each other -
they will not understand messages from other tests. By the
way, the same problem can appear in real applications too;
* do not binding again a URI passed by test-run into the
test and closed here. If a test closes a URI given to it,
it can't be sure, that next bind() will be successful -
test-run could already reuse it.
Follow up #3234
---
src/lua/swim.lua | 1 +
test/swim/box.lua | 22 ++++++++++++++++++++++
test/swim/swim.result | 26 +++++++++++++++-----------
test/swim/swim.test.lua | 16 ++++++++--------
4 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/src/lua/swim.lua b/src/lua/swim.lua
index d3d6b01e9..4893d5767 100644
--- a/src/lua/swim.lua
+++ b/src/lua/swim.lua
@@ -804,6 +804,7 @@ local swim_not_configured_mt = {
__index = {
delete = swim_delete,
is_configured = swim_is_configured,
+ set_codec = swim_set_codec,
},
__serialize = swim_serialize
}
diff --git a/test/swim/box.lua b/test/swim/box.lua
index b6a39575e..a603777e0 100644
--- a/test/swim/box.lua
+++ b/test/swim/box.lua
@@ -7,6 +7,28 @@ listen_port = require('uri').parse(listen_uri).service
box.cfg{}
+--
+-- SWIM instances, using broadcast, should protect themselves
+-- with encryption. Otherwise they can accidentally discover
+-- SWIM instances from other tests.
+--
+enc_key = box.info.uuid
+enc_algo = 'aes128'
+
+--
+-- Wrap swim.new with a codec to prevent test workers affecting
+-- each other.
+--
+local original_new = swim.new
+swim.new = function(...)
+ local s, err = original_new(...)
+ if s == nil then
+ return s, err
+ end
+ assert(s:set_codec({algo = enc_algo, key = enc_key, key_size = 16}))
+ return s
+end
+
function uuid(i)
local min_valid_prefix = '00000000-0000-1000-8000-'
if i < 10 then
diff --git a/test/swim/swim.result b/test/swim/swim.result
index 1b5ae2b0f..436d4e579 100644
--- a/test/swim/swim.result
+++ b/test/swim/swim.result
@@ -333,7 +333,7 @@ s1:delete()
s1 = swim.new({uuid = uuid(1), uri = uri()})
---
...
-s2 = swim.new({uuid = uuid(2), uri = listen_uri})
+s2 = swim.new({uuid = uuid(2), uri = uri()})
---
...
s1.probe_member()
@@ -361,7 +361,7 @@ s1:size()
---
- 1
...
-s1:probe_member(listen_uri)
+s1:probe_member(s2:self():uri())
---
- true
...
@@ -698,10 +698,10 @@ self:is_dropped()
s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01})
---
...
-s2 = swim.new({uuid = uuid(2), uri = listen_port, heartbeat_rate = 0.01})
+s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01})
---
...
-s1:add_member({uuid = uuid(2), uri = listen_port})
+s1:add_member({uuid = uuid(2), uri = s2:self():uri()})
---
- true
...
@@ -828,7 +828,7 @@ s:delete()
--
-- Payload caching.
--
-s1 = swim.new({uuid = uuid(1), uri = uri(listen_port), heartbeat_rate = 0.01})
+s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01})
---
...
s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01})
@@ -902,7 +902,7 @@ s1_view:payload()
...
s1_view:incarnation()
---
-- 2
+- 3
...
s1:cfg({heartbeat_rate = 0.01})
---
@@ -928,7 +928,7 @@ p
...
s1_view:incarnation()
---
-- 2
+- 3
...
s1:delete()
---
@@ -1099,7 +1099,7 @@ s1:set_codec(cfg)
---
- true
...
--- S2 does not use encryption and can't decode the ping.
+-- S2 uses different encryption and can't decode the ping.
s1:probe_member(s2:self():uri())
---
- true
@@ -1199,12 +1199,16 @@ s1:probe_member(s2:self():uri())
---
- true
...
-while s1:size() ~= 2 do fiber.sleep(0.01) end
+while s1:member_by_uuid(s2:self():uuid()) == nil do fiber.sleep(0.01) end
---
...
-s2:size()
+s2:member_by_uuid(s1:self():uuid())
---
-- 2
+- uri: 127.0.0.1:<port>
+ status: alive
+ incarnation: 1
+ uuid: 00000000-0000-1000-8000-000000000001
+ payload_size: 0
...
s1:delete()
---
diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua
index b344c69be..a3eac9b46 100644
--- a/test/swim/swim.test.lua
+++ b/test/swim/swim.test.lua
@@ -114,7 +114,7 @@ s1:remove_member(uuid(1))
s1:delete()
s1 = swim.new({uuid = uuid(1), uri = uri()})
-s2 = swim.new({uuid = uuid(2), uri = listen_uri})
+s2 = swim.new({uuid = uuid(2), uri = uri()})
s1.probe_member()
s1:probe_member()
s1:probe_member(true)
@@ -122,7 +122,7 @@ s1:probe_member(true)
s1:probe_member('127.0.0.1:1')
fiber.yield()
s1:size()
-s1:probe_member(listen_uri)
+s1:probe_member(s2:self():uri())
while s1:size() ~= 2 do fiber.sleep(0.01) end
s2:size()
@@ -233,8 +233,8 @@ self:is_dropped()
-- Check payload dissemination.
--
s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01})
-s2 = swim.new({uuid = uuid(2), uri = listen_port, heartbeat_rate = 0.01})
-s1:add_member({uuid = uuid(2), uri = listen_port})
+s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01})
+s1:add_member({uuid = uuid(2), uri = s2:self():uri()})
while s2:size() ~= 2 do fiber.sleep(0.01) end
s1_view = s2:member_by_uuid(uuid(1))
s1_view:payload()
@@ -269,7 +269,7 @@ s:delete()
--
-- Payload caching.
--
-s1 = swim.new({uuid = uuid(1), uri = uri(listen_port), heartbeat_rate = 0.01})
+s1 = swim.new({uuid = uuid(1), uri = uri(), heartbeat_rate = 0.01})
s2 = swim.new({uuid = uuid(2), uri = uri(), heartbeat_rate = 0.01})
s1_self = s1:self()
_ = s1:add_member({uuid = s2:self():uuid(), uri = s2:self():uri()})
@@ -371,7 +371,7 @@ cfg.key = '1234567812345678'
cfg.key_size = 16
s1:set_codec(cfg)
--- S2 does not use encryption and can't decode the ping.
+-- S2 uses different encryption and can't decode the ping.
s1:probe_member(s2:self():uri())
fiber.sleep(0.01)
s1:size()
@@ -407,8 +407,8 @@ s2:size()
s1:set_codec({algo = 'none'})
s2:set_codec({algo = 'none'})
s1:probe_member(s2:self():uri())
-while s1:size() ~= 2 do fiber.sleep(0.01) end
-s2:size()
+while s1:member_by_uuid(s2:self():uuid()) == nil do fiber.sleep(0.01) end
+s2:member_by_uuid(s1:self():uuid())
s1:delete()
s2:delete()
--
2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-05-22 19:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-22 19:52 [tarantool-patches] [PATCH 0/5] SWIM bug fixes Vladislav Shpilevoy
2019-05-22 19:52 ` [tarantool-patches] [PATCH 1/5] swim: fix an obvious leak in swim_delete() Vladislav Shpilevoy
2019-05-22 19:52 ` [tarantool-patches] [PATCH 2/5] swim: fix an obvious use-after-free Vladislav Shpilevoy
2019-05-22 19:52 ` [tarantool-patches] [PATCH 3/5] swim: fix flaky parts in swim/swim.test.lua Vladislav Shpilevoy
2019-05-22 19:52 ` [tarantool-patches] [PATCH 4/5] swim: be ready to idle round steps when net is slow Vladislav Shpilevoy
2019-05-22 19:52 ` Vladislav Shpilevoy [this message]
2019-05-22 21:14 ` [tarantool-patches] Re: [PATCH 0/5] SWIM bug fixes Vladislav Shpilevoy
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=e074202e0c7f785a780eb0f71d7e375a3d00803f.1558554655.git.v.shpilevoy@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH 5/5] swim: allow to set codec before cfg' \
/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