to_IxHash
/
;
use
if
$ENV
{MONGOVERBOSE},
qw/Log::Any::Adapter Stderr/
;
build_client
get_test_db
server_version
server_type
clear_testdbs
get_unique_collection
skip_unless_mongod
skip_unless_failpoints_available
skip_unless_transactions
remap_hashref_to_snake_case
to_snake_case
set_failpoint
clear_failpoint
/
;
skip_unless_mongod();
skip_unless_transactions();
my
$conn
= build_client(
wtimeout
=>
undef
);
my
$db
= get_test_db(
$conn
);
my
$test_coll
= get_unique_collection(
$db
,
'txn_convenient_api'
);
$test_coll
->drop;
my
$test_session
=
$conn
->start_session({});
subtest
'Custom Error'
=>
sub
{
eval
{
no
warnings
'redefine'
;
*MongoDB::ClientSession::_within_time_limit
=
sub
{0};
$test_session
->with_transaction(
sub
{
MongoDB::Error->throw(
message
=>
'Custom Error'
,
error_labels
=> [
'TransientTransactionError'
],
)
},
);
1
} or
do
{
my
$err
= $@;
like(
$err
,
qr/Custom\s+Error/
,
'test callback throws custom exception'
);
};
};
subtest
'Return Value'
=>
sub
{
my
$exp_test_ret_value
=
'Foo'
;
is(
$test_session
->with_transaction(
sub
{
'Foo'
},
),
$exp_test_ret_value
,
'test callback returns value'
);
is(
$test_session
->with_transaction(
sub
{
$test_coll
->insert_one({});
return
'Foo'
},
),
$exp_test_ret_value
,
'test callback returns value'
);
};
clear_testdbs;
done_testing;