I’m unable to verify the expected transaction behavior.
I made this unit test:
module namespace test = 'http://basex.org/modules/xqunit-tests';
declare variable $test:dbName := string('test_' || replace(string(current-dateTime()),'[:\.]', '_'));
declare %unit:before-module updating function test:setUp() {
update:output(prof:dump('test:setUp(): Creating database ' || $test:dbName)),
db:create($test:dbName)
};
declare %unit:after-module updating function test:tearDown() {
update:output(prof:dump('test:tearDown(): Dropping database ' || $test:dbName)),
if (db:exists($test:dbName))
then
try {
db:drop($test:dbName)
} catch * {
update:output(prof:dump('test:tearDown(): Error ' || $err:code || ' from db:drop(): ' || $err:description))
}
else update:output("test:tearDown(): Database " || $test:dbName || " does not exist.")
};
declare %unit:test updating function test:addToDb() {
update:output(prof:dump('test:addToDb(): Adding doc to database ' || $test:dbName)),
try {
db:add($test:dbName, <doc time="{current-dateTime()}">doc 1</doc>, 'doc-01.xml')
} catch * {
update:output(prof:dump('test:addToDb(): Error ' || $err:code || ' from db:add(): ' || $err:description))
}
};
(: ==== End of m odule ==== :)
And it produces this result:
Evaluating:
"test:setUp(): Creating database test_2022-02-01T11_59_34_703-06_00"
"test:addToDb(): Adding doc to database test_2022-02-01T11_59_34_718-06_00"
"test:addToDb(): Error db:open from db:add(): Database 'test_2022-02-01T11_59_34_718-06_00' was not found."
"test:tearDown(): Dropping database test_2022-02-01T11_59_34_727-06_00"
The database is created but is not dropped and obviously not updated.
If my test is legit then this suggests that before-module and after-module are not separate transactions.
Cheers,
E.
_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
LinkedIn | Twitter | YouTube | Facebook
From:
Christian Grün <christian.gruen@gmail.com>
Date: Monday, January 31, 2022 at 11:28 AM
To: Andrew Sales <andrew@andrewsales.com>
Cc: Eliot Kimber <eliot.kimber@servicenow.com>, basex-talk@mailman.uni-konstanz.de <basex-talk@mailman.uni-konstanz.de>
Subject: Re: [basex-talk] Techniques for Unit Testing Updating Operations
[External Email]
That’s precisely what happens. I have added this piece of information
to our documentation. – Thanks, Christian
On Mon, Jan 31, 2022 at 5:54 PM Andrew Sales <andrew@andrewsales.com> wrote:
>>
>> But maybe the test runner runs unit:before-module() as a separate transaction?
>
>
> That does look to be the behaviour -- the phrase "This extension is e. g. helpful if the results of updates need to be tested." and the accompanying code snippet [1] imply as much to me, but it would be good if the BaseX dev team could confirm, and the documentation
make this explicit.
>
> Andrew
>
> [1] https://urldefense.com/v3/__https://docs.basex.org/wiki/Unit_Module*unit:before__;Iw!!N4vogdjhuJM!QaGgfyLTQYT7a_H1uFaAoJJOpRxHYVQRJ1n_ZoFbEsnfmodXuczcubZkHyMDVWbI-ZMIIQ$