diff --git a/lib/resty/jit-uuid.lua b/lib/resty/jit-uuid.lua index e8893f03b97eb7566697f9b634adf69c506d6d96..b8dcbd22d72955f2504da632facb3f238e5eba4c 100644 --- a/lib/resty/jit-uuid.lua +++ b/lib/resty/jit-uuid.lua @@ -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), diff --git a/t/04-v3.t b/t/04-v3.t index d221d103d97b1c4f282af065f72e3d13e0a12f07..34e6d1ed122693999d32b3b562fe5fe8862eeb6b 100644 --- a/t/04-v3.t +++ b/t/04-v3.t @@ -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] diff --git a/t/05-v5.t b/t/05-v5.t index 3f4f492705d066b07e4194ba69c0f9662de9b97d..1c7384ef59223182f6043536dbd39751df443d35 100644 --- a/t/05-v5.t +++ b/t/05-v5.t @@ -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]