New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverage not being reported when DBMS_SCHEDULER.RUN_JOB is in tests #1271
Comments
Hi @jasonlyle88 |
Apologies, you are correct, i was not clear on the coverage. Lets say I have the following: PKG_A TEST_PKG_A (unit test suite for PKG_A) Without Now, lets say I put a test that calls So if any test is included that runs In my case, there was an instance where a job was release with a product with a typo in the job definition, so the job always failed, no matter what. So What I want to prove out here is just that the job runs successfully by running the job with If the job runs code in something for which I am reporting coverage, I would also think that code execution would count towards the line coverage. I have not checked the content of the DBMS_PROFILER tables in the framework schema, I didn't know where to look before you said that! Hope this helps clear things up, please feel free to as for more clarification if not! |
You are correct. |
If profiler is not profiling any run inside scheduler, then that is one issue (if it is a problem). And it would be an oracle issue, not your issue. However, all usage reporting being lost from other test runs in UTPLSQL is still potentially a UTPLSQL issue. What I mean by this is the use case explained above where I run all test packages, but 0% usage is reported even though there are tests not running jobs that should be collecting profiler data. |
Hi @jasonlyle88 , sorry have not chance to finish :) Clicked entered and you replied while was editing comment. create or replace PROCEDURE ptest IS
l_number number;
BEGIN
select 1 into l_number from dual;
END;
/ And execute delete from ut3_develop.PLSQL_PROFILER_DATA;
delete from ut3_develop.PLSQL_PROFILER_UNITS;
delete from ut3_develop.PLSQL_PROFILER_RUNS;
commit;
DECLARE
l_result BINARY_INTEGER;
BEGIN
l_result := DBMS_PROFILER.start_profiler(run_comment => 'do_something: ' || SYSDATE);
ptest;
l_result := DBMS_PROFILER.stop_profiler;
END;
/
select * from PLSQL_PROFILER_DATA;
select * from PLSQL_PROFILER_UNITS;
select * from PLSQL_PROFILER_RUNS;
`
We can see a units provided in the run.
Then we execute our scheduler
```sql
delete from ut3_develop.PLSQL_PROFILER_DATA;
delete from ut3_develop.PLSQL_PROFILER_UNITS;
delete from ut3_develop.PLSQL_PROFILER_RUNS;
commit;
DECLARE
l_result BINARY_INTEGER;
BEGIN
l_result := DBMS_PROFILER.start_profiler(run_comment => 'do_something: ' || SYSDATE);
DBMS_SCHEDULER.RUN_JOB(job_name => '"UT3_DEVELOP"."TEST"', USE_CURRENT_SESSION => TRUE);
l_result := DBMS_PROFILER.stop_profiler;
END;
/
select * from PLSQL_PROFILER_DATA;
select * from PLSQL_PROFILER_UNITS;
select * from PLSQL_PROFILER_RUNS; As you can see there are no data created, even more interesting a run in profiler takes 0sec which indicates a is being closed by something outside us. |
To prove fact that is being closed abruptly you can put : |
That is very interesting! It does indeed to be all on the Oracle side. Great debugging, thanks for the help getting through that. I had not considered putting the DBMS_SCHEDULER_RUN.RUN_JOB in a helper procedure with pragma autonomous. I can give that a try and let you know if it works for not! |
Hi @jasonlyle88 I think I found a workaround for you. If you try this it's working. I can assume is due to fact that a profile has to be start and stopped within a session and even create or replace PROCEDURE ptest IS
l_number number;
BEGIN
select 1 into l_number from dual;
END;
/
create or replace package test_ptest as
-- %suite
-- %displayname(Scheduler cov)
-- %test
-- %displayname(test me)
procedure test_ptestproc;
-- %test
-- %displayname(test me 1)
procedure test_ptestproc1;
end;
/
create or replace package body test_ptest as
procedure run_job is
l_coverage_run_id raw(32767);
pragma autonomous_transaction;
begin
ut_runner.coverage_start(l_coverage_run_id);
DBMS_SCHEDULER.RUN_JOB(job_name => 'TEST', use_current_session => true);
ut_runner.coverage_stop();
end;
procedure test_ptestproc is
begin
run_job;
ut3_develop.ut.expect( 1 ).to_( equal(1) );
end;
procedure test_ptestproc1 is
begin
ptest;
ut3_develop.ut.expect( 1 ).to_( equal(1) );
end;
end;
/ and then executing: select * from table(ut.run(ut_coverage_html_reporter())); Produce a correct results. ...
<div class="source_table" id="738C9A9AB3B9CCB3B488306B6395C96D"><div class="header"> <h3>UT3_DEVELOP.PTEST</h3><h4><span class="green">100 %</span> lines covered</h4><div> <b>1</b> relevant lines. <span class="green"><b>1</b> lines covered</span> and <span class="red"><b>0</b> lines missed</span></div></div><pre><ol>
... In the test where we |
Wow, awesome! Thank you so much. I definitely would not have gotten that. I will give this a try and report back! |
Hey @lwasylowm, I think that is working because DBMS_SCHEDULER.RUN_JOB isn't actually getting executed. I switched from the ut_coverage_html_reporter to the ut_documentation_reporter and it fails on the Any further thoughts? |
You right it was missing: |
What's funny is that creation of the job and execution works ok :) procedure run_job is
l_coverage_run_id raw(32) := sys_guid();
pragma autonomous_transaction;
begin
ut3_develop.ut_runner.coverage_start(l_coverage_run_id);
dbms_scheduler.create_job(
job_name => 'TEST2',
job_type => 'PLSQL_BLOCK',
job_action => 'begin ptest; end;',
start_date => sysdate,
enabled => TRUE,
auto_drop => TRUE,
comments => 'one-time-job'
);
ut3_develop.ut_runner.coverage_stop();
commit;
end;
618 29-SEP-23 10.06.18.734013000 PM GMT UT3_DEVELOP TEST2 SUCCEEDED |
Hello, I have similar problems: |
Describe the bug
When running code coverage, I get 0% code coverage is
DBMS_SCHEDULER.RUN_JOB
is called in the testsbelow is my test:
commenting out the
DBMS_SCHEDULER.RUN_JOB
call returns all the code coverages to expected values.Provide version info
Information about utPLSQL and Database version,
Information about client software
This was run in SQLDeveloper and SQLcl (latest versions)
To Reproduce
Create a test that runs any job with
DBMS_SCHEDULER.RUN_JOB
Expected behavior
Code coverage to be reported correctly
The text was updated successfully, but these errors were encountered: