From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id CE0C06EC5B; Mon, 12 Apr 2021 01:36:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CE0C06EC5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618180614; bh=C1IN1opE54uEWHPh3yeXZfoRBSEKZ2r2jbIcNCwIiEs=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=HVg3F4encLNxn2yi9GTGTMb+xzibO+dqbQWusy+WxVVzYodU3kUwPVU8xkenN3wi3 apMDsK6HJxwuVAiOTEwD6KoIah3hJWzyfCnoa7aphXnpOH0aw1kcEs7leu/zEuGQA7 TVNfnjcymMhVCh3sd3YZ/3T+KkhH760ZFT3hTeqg= Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 072F26EC5B for ; Mon, 12 Apr 2021 01:36:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 072F26EC5B Received: by mail-lj1-f175.google.com with SMTP id r22so2328502ljc.5 for ; Sun, 11 Apr 2021 15:36:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dXQoZKhNoR0ckuJrX/BxYgYW8kYscO93QxaX+AqAG4E=; b=av4/8T6IYBMk5FKN+yIV4QeTYENm1pM7cAxztCv84aFOTVpm1zOHPWAZetDNR1rIiN +wU83crUyMRg4cbmZozUC+MAmpCbc/lw2vAYC0RtTznVthlOzCYVpL/mkY2i2CnU0Uu1 soPf+bTINJkeeXNAIcWyUnqaDp5806cBVXlO7TnE4lYX0opefM4dTEbye/3Po9oJrFVo K/zfd1Kr42+d9NfANYYEUu7koW0jeNXuHjPNzTSvl4CWGnJkftip0CjLMrqB90uzZVK+ s6ekH7dRYw9bIsqpsss79p+dp8S27aKDH2SGiOvdCTdRgsQT09leOnGfLcghu4CukiE5 +Dcw== X-Gm-Message-State: AOAM532Z1O0NVVBb8IAurWb8/BpoxYpEdl6V+UmR5E51jRVMQzwEPQPv aTiqU535dtZZXnFu3Z5aVkunacxiuLg= X-Google-Smtp-Source: ABdhPJyfgeeQVUIN3zjs42I2QB1LBGZgwE2Cv6hxL59ANHAvMVhYAstIQx2HQAuBNcNypadUx8BaVw== X-Received: by 2002:a2e:90d1:: with SMTP id o17mr8182381ljg.92.1618180611821; Sun, 11 Apr 2021 15:36:51 -0700 (PDT) Received: from grain.localdomain ([5.18.199.94]) by smtp.gmail.com with ESMTPSA id j14sm1858891lfg.134.2021.04.11.15.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Apr 2021 15:36:50 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id DEB73560112; Mon, 12 Apr 2021 01:36:49 +0300 (MSK) Date: Mon, 12 Apr 2021 01:36:49 +0300 To: Vladislav Shpilevoy Message-ID: References: <20210408164151.1759348-1-gorcunov@gmail.com> <20210408164151.1759348-7-gorcunov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.5 (2021-01-21) Subject: Re: [Tarantool-patches] [PATCH v21 6/6] test: add box.lib test X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: tml Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Sun, Apr 11, 2021 at 05:43:02PM +0200, Vladislav Shpilevoy wrote: > Thanks for the patch! > > See below 4 comments, my diff in the end of the email, and on > the branch in a separate commit. Vlad, here is a diff on top. Please take a look. I didn't push out anything yet, because need to squash them first. --- Subject: [PATCH] merged test Signed-off-by: Cyrill Gorcunov --- test/box/lib.result | 87 ++++++++++++++++++++++++++++++++++++------- test/box/lib.test.lua | 49 ++++++++++++++++++------ 2 files changed, 110 insertions(+), 26 deletions(-) diff --git a/test/box/lib.result b/test/box/lib.result index 58acb9c06..5067e9b36 100644 --- a/test/box/lib.result +++ b/test/box/lib.result @@ -356,10 +356,19 @@ box.func['cfunc.cfunc_add']:call({1, 2}) | - 3 | ... +-- Now we have 2 refs for low level module (when function +-- is loaded for first time from box.schema.func it takes +-- two refs: one for module itself and one for for the function, +-- this is because there is no explicit "load" procedure for +-- box.schema.func, next loads from the same module via box.schema.func +-- interface grabs the module from cache and add only one reference). +-- +-- So we have 2 refs for box.schema.func and one for box.lib +-- interface which grabs the same module. old_module = box.lib.load('cfunc') | --- | ... -assert(old_module['debug_refs'] == 3) -- box.lib + 2 box.schema.func +assert(old_module['debug_refs'] == 3) | --- | - true | ... @@ -392,11 +401,12 @@ box.func['cfunc.cfunc_add']:call({1, 2}) | - 13 | ... --- The box.lib instance should carry own --- references to the module and old --- function. And reloading must not --- affect old functions. Thus one for --- box.lib and one for box.lib function. +-- The box.lib instance should carry own references to +-- the module and old function. And reloading must not +-- affect old functions. Thus one for box.lib _module_ and +-- one for box.lib _function_. The reloaded box.schema.func +-- will carry own two references for reloaded module and +-- bound function. assert(old_module['debug_refs'] == 2) | --- | - true @@ -414,10 +424,9 @@ old_module:unload() | - true | ... --- Same time the reload should update --- low level module cache, thus two --- for box and box function plus one --- new box.lib. +-- Same time the reload should update low level module cache, +-- thus we load a new instance from updated cache entry which +-- has 2 references already and thus we add one more reference. new_module = box.lib.load('cfunc') | --- | ... @@ -432,10 +441,6 @@ box.func['cfunc.cfunc_add']:call({1, 2}) | - 13 | ... --- Cleanup. -_ = pcall(fio.unlink(cfunc_path)) - | --- - | ... new_module:unload() | --- | - true @@ -443,3 +448,57 @@ new_module:unload() box.schema.func.drop('cfunc.cfunc_add') | --- | ... + +-- Now lets try to figure out if __gc works as expected. +module1 = box.lib.load('cfunc') + | --- + | ... +module2 = box.lib.load('cfunc') + | --- + | ... +assert(module1['debug_module_ptr'] == module2['debug_module_ptr']) + | --- + | - true + | ... +assert(module1['debug_refs'] == 2) + | --- + | - true + | ... +cfunc_add = module2:load('cfunc_add') + | --- + | ... +assert(module1['debug_refs'] == 3) + | --- + | - true + | ... +module2 = nil + | --- + | ... +collectgarbage('collect') + | --- + | - 0 + | ... +assert(module1['debug_refs'] == 2) + | --- + | - true + | ... +cfunc_add = nil + | --- + | ... +collectgarbage('collect') + | --- + | - 0 + | ... +assert(module1['debug_refs'] == 1) + | --- + | - true + | ... +module1:unload() + | --- + | - true + | ... + +-- Cleanup. +_ = pcall(fio.unlink(cfunc_path)) + | --- + | ... diff --git a/test/box/lib.test.lua b/test/box/lib.test.lua index e0e4b9e4d..93cea90b6 100644 --- a/test/box/lib.test.lua +++ b/test/box/lib.test.lua @@ -139,8 +139,17 @@ box.schema.func.create('cfunc.cfunc_add', {language = "C"}) box.schema.user.grant('guest', 'execute', 'function', 'cfunc.cfunc_add') box.func['cfunc.cfunc_add']:call({1, 2}) +-- Now we have 2 refs for low level module (when function +-- is loaded for first time from box.schema.func it takes +-- two refs: one for module itself and one for for the function, +-- this is because there is no explicit "load" procedure for +-- box.schema.func, next loads from the same module via box.schema.func +-- interface grabs the module from cache and add only one reference). +-- +-- So we have 2 refs for box.schema.func and one for box.lib +-- interface which grabs the same module. old_module = box.lib.load('cfunc') -assert(old_module['debug_refs'] == 3) -- box.lib + 2 box.schema.func +assert(old_module['debug_refs'] == 3) old_func = old_module:load('cfunc_add') assert(old_module['debug_refs'] == 4) -- plus function instance old_func(1, 2) @@ -152,27 +161,43 @@ fio.symlink(cfunc4_path, cfunc_path) box.schema.func.reload("cfunc") box.func['cfunc.cfunc_add']:call({1, 2}) --- The box.lib instance should carry own --- references to the module and old --- function. And reloading must not --- affect old functions. Thus one for --- box.lib and one for box.lib function. +-- The box.lib instance should carry own references to +-- the module and old function. And reloading must not +-- affect old functions. Thus one for box.lib _module_ and +-- one for box.lib _function_. The reloaded box.schema.func +-- will carry own two references for reloaded module and +-- bound function. assert(old_module['debug_refs'] == 2) old_func(1, 2) old_func:unload() old_module:unload() --- Same time the reload should update --- low level module cache, thus two --- for box and box function plus one --- new box.lib. +-- Same time the reload should update low level module cache, +-- thus we load a new instance from updated cache entry which +-- has 2 references already and thus we add one more reference. new_module = box.lib.load('cfunc') assert(new_module['debug_refs'] == 3) -- Box function should carry own module. box.func['cfunc.cfunc_add']:call({1, 2}) --- Cleanup. -_ = pcall(fio.unlink(cfunc_path)) new_module:unload() box.schema.func.drop('cfunc.cfunc_add') + +-- Now lets try to figure out if __gc works as expected. +module1 = box.lib.load('cfunc') +module2 = box.lib.load('cfunc') +assert(module1['debug_module_ptr'] == module2['debug_module_ptr']) +assert(module1['debug_refs'] == 2) +cfunc_add = module2:load('cfunc_add') +assert(module1['debug_refs'] == 3) +module2 = nil +collectgarbage('collect') +assert(module1['debug_refs'] == 2) +cfunc_add = nil +collectgarbage('collect') +assert(module1['debug_refs'] == 1) +module1:unload() + +-- Cleanup. +_ = pcall(fio.unlink(cfunc_path)) -- 2.30.2