提交 a3e16046 编写于 作者: S spacewander 提交者: Thibault Charbonnier

fix(v3/v5) do not share namespace between factories

The buffer should not be shared among factories. By removing the concat
out of each call, we also speed up the generation.
Signed-off-by: NThibault Charbonnier <thibaultcha@me.com>
上级 2718b295
......@@ -274,13 +274,14 @@ do
end
assert(i == 16, "invalid binary namespace buffer length")
local ns = concat(buf)
return function(name)
if type(name) ~= 'string' then
return nil, 'name must be a string'
end
local hash, ver, var = hash_fn(concat(buf, ''), name)
local hash, ver, var = hash_fn(ns, name)
return (fmt('%s-%s-%s%s-%s%s-%s', sub(hash, 1, 8),
sub(hash, 9, 12),
......
......@@ -198,3 +198,27 @@ qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):6 loop\]/
--- no_error_log
[error]
-- NYI:
=== TEST 9: generated UUID from each factory should be independent
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua_block {
local uuid = require 'resty.jit-uuid'
local factory = uuid.factory_v3('1b985f4a-06be-11e6-aff4-ff8d14e25128')
ngx.say(factory('hello'))
uuid.factory_v3('e6ebd542-06ae-11e6-8e82-bba81706b27d')
ngx.say(factory('hello'))
}
}
--- request
GET /t
--- response_body
5dcd9919-b318-3ef8-bfb1-c81f44c72084
5dcd9919-b318-3ef8-bfb1-c81f44c72084
--- no_error_log
[error]
......@@ -198,3 +198,27 @@ qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):6 loop\]/
--- no_error_log
[error]
-- NYI:
=== TEST 9: generated UUID from each factory should be independent
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua_block {
local uuid = require 'resty.jit-uuid'
local factory = uuid.factory_v5('1b985f4a-06be-11e6-aff4-ff8d14e25128')
ngx.say(factory('hello'))
uuid.factory_v5('e6ebd542-06ae-11e6-8e82-bba81706b27d')
ngx.say(factory('hello'))
}
}
--- request
GET /t
--- response_body
e90a1bfc-d349-5ec0-89fe-b29f2419624b
e90a1bfc-d349-5ec0-89fe-b29f2419624b
--- no_error_log
[error]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册