Skip to content

Commit a580f91

Browse files
committed
fix: use fixed date in autonomous transaction test for determinism
1 parent 36e439f commit a580f91

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/pl/plisql/src/expected/plisql_autonomous.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,29 +449,29 @@ SELECT id, msg FROM autonomous_test WHERE id = 53;
449449
-- Test 19: Function returning DATE (pass-by-value)
450450
-- Tests date type handling
451451
--
452-
CREATE OR REPLACE FUNCTION test_function_date(p_days_offset INT) RETURN DATE AS
452+
CREATE OR REPLACE FUNCTION test_function_date(p_base_date DATE, p_days_offset INT) RETURN DATE AS
453453
DECLARE
454454
PRAGMA AUTONOMOUS_TRANSACTION;
455455
v_result DATE;
456456
BEGIN
457-
v_result := CURRENT_DATE + p_days_offset;
457+
v_result := p_base_date + p_days_offset;
458458
INSERT INTO autonomous_test VALUES (54, 'date: ' || v_result::TEXT, 'committed');
459459
RETURN v_result;
460460
END;
461461
/
462462
COMMIT;
463463
WARNING: there is no transaction in progress
464-
-- Returns date 7 days from now
465-
SELECT test_function_date(7) AS date_result;
464+
-- Returns date 7 days from base date (using fixed date for deterministic test)
465+
SELECT test_function_date('2025-01-01'::DATE, 7) AS date_result;
466466
date_result
467467
-------------
468-
2025-12-08
468+
2025-01-08
469469
(1 row)
470470

471471
SELECT id, msg FROM autonomous_test WHERE id = 54;
472472
id | msg
473473
----+------------------
474-
54 | date: 2025-12-08
474+
54 | date: 2025-01-08
475475
(1 row)
476476

477477
--
@@ -534,6 +534,6 @@ DROP FUNCTION test_function_text(TEXT);
534534
DROP FUNCTION inner_function(INT);
535535
DROP FUNCTION outer_function(INT);
536536
DROP FUNCTION test_function_numeric(NUMERIC);
537-
DROP FUNCTION test_function_date(INT);
537+
DROP FUNCTION test_function_date(DATE, INT);
538538
DROP FUNCTION test_function_boolean(INT);
539539
DROP TABLE autonomous_test;

src/pl/plisql/src/pl_exec.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static void plisql_anonymous_return_out_parameter(PLiSQL_execstate * estate, PLi
500500
*
501501
* @param func The PLiSQL_function descriptor to execute.
502502
* @param fcinfo Call context and argument/return storage (FunctionCallInfo).
503-
* May be NULL in some internal contexts.
503+
* Must be non-NULL for executable calls.
504504
* @param simple_eval_estate Optional EState to use for simple-expression
505505
* evaluation; pass NULL to use the session-shared evaluator.
506506
* @param simple_eval_resowner Optional ResourceOwner associated with
@@ -525,9 +525,14 @@ plisql_exec_function(PLiSQL_function * func, FunctionCallInfo fcinfo,
525525
int i;
526526
int rc;
527527

528-
char function_from = plisql_function_from(fcinfo);
528+
char function_from;
529529
bool anonymous_have_outparam = false;
530530

531+
/* fcinfo must be non-NULL for executable calls */
532+
Assert(fcinfo != NULL);
533+
534+
function_from = plisql_function_from(fcinfo);
535+
531536
/*
532537
* Setup the execution state
533538
*/

src/pl/plisql/src/sql/plisql_autonomous.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,21 @@ SELECT id, msg FROM autonomous_test WHERE id = 53;
390390
-- Test 19: Function returning DATE (pass-by-value)
391391
-- Tests date type handling
392392
--
393-
CREATE OR REPLACE FUNCTION test_function_date(p_days_offset INT) RETURN DATE AS
393+
CREATE OR REPLACE FUNCTION test_function_date(p_base_date DATE, p_days_offset INT) RETURN DATE AS
394394
DECLARE
395395
PRAGMA AUTONOMOUS_TRANSACTION;
396396
v_result DATE;
397397
BEGIN
398-
v_result := CURRENT_DATE + p_days_offset;
398+
v_result := p_base_date + p_days_offset;
399399
INSERT INTO autonomous_test VALUES (54, 'date: ' || v_result::TEXT, 'committed');
400400
RETURN v_result;
401401
END;
402402
/
403403

404404
COMMIT;
405405

406-
-- Returns date 7 days from now
407-
SELECT test_function_date(7) AS date_result;
406+
-- Returns date 7 days from base date (using fixed date for deterministic test)
407+
SELECT test_function_date('2025-01-01'::DATE, 7) AS date_result;
408408
SELECT id, msg FROM autonomous_test WHERE id = 54;
409409

410410
--
@@ -449,6 +449,6 @@ DROP FUNCTION test_function_text(TEXT);
449449
DROP FUNCTION inner_function(INT);
450450
DROP FUNCTION outer_function(INT);
451451
DROP FUNCTION test_function_numeric(NUMERIC);
452-
DROP FUNCTION test_function_date(INT);
452+
DROP FUNCTION test_function_date(DATE, INT);
453453
DROP FUNCTION test_function_boolean(INT);
454454
DROP TABLE autonomous_test;

0 commit comments

Comments
 (0)