Skip to content

Commit

Permalink
LDEV-5206 improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Dec 18, 2024
1 parent 25254df commit 982c5e6
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 14 deletions.
106 changes: 93 additions & 13 deletions test/tickets/LDEV5206.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,87 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" {
};

function run( testResults, testBox ){
describe( "LDEV-5206 execution logs", function(){

describe( "LDEV-5206 ConsoleExecutionLog", function(){
it( "test ConsoleExecutionLog", function(){
enableExecutionLog("lucee.runtime.engine.ConsoleExecutionLog",{
"stream-type": "out",
"unit": "milli",
"min-time": 100,
//"min-time": 100,
"snippet": true
});
systemOutput("", true);
systemOutput("Logging executionLog to console", true);
local.result = _InternalRequest(
template : "#uri#/ldev5206.cfm"
);
systemOutput("Logging debugEntries to console", true);
systemOutput(getDebugEntry(), true);
systemOutput("finished", true);
});
});
describe( "LDEV-5206 DebugExecutionLog", function(){
it( "test DebugExecutionLog - cfm ", function(){
var logs = getDebugLogs();
expect( len( logs ) ).toBe( 1 );
var log = logs[ 1 ];
expect( log ).toHaveKey( "pageParts" );
var pageParts = log.pageParts;
expect( pageParts ).toBeQuery();
//systemOutput( pageParts.toString(), true );
pageParts = _toPartsStruct( pageParts );
//systemOutput( pageParts, true );

var key = "ldev5206.cfm:3:3";
expect( pageParts ).toHaveKey( key );
expect( pageParts[ key ].snippet ).toBe( "sleep(5)" );

key = "ldev5206.cfm:5:5";
expect( pageParts ).toHaveKey( key );
expect( pageParts[ key ].snippet ).toBe( "cfc = new ldev5206()" );
});

xit( "test DebugExecutionLog - cfm parts member", function(){
var logs = getDebugLogs();
expect( len( logs ) ).toBe( 1 );
var log = logs[ 1 ];
expect( log ).toHaveKey( "pageParts" );
var pageParts = log.pageParts;
expect( pageParts ).toBeQuery();
pageParts = _toPartsStruct( pageParts );

key = "ldev5206.cfm:6:6";
expect( pageParts ).toHaveKey( key );
expect( pageParts[ key ].snippet ).toBe( "cfc.doSleep()" ); // LDEV-5207

key = "ldev5206.cfm:9:9";
expect( pageParts ).toHaveKey( key );
expect( pageParts[ key ].snippet ).toBe( "cfc.doSleep()" ); // LDEV-5207
});

xit( "test DebugExecutionLog - cfc parts ", function(){
var logs = getDebugLogs();
expect( len( logs ) ).toBe( 1 );
var log = logs[ 1 ];
expect( log ).toHaveKey( "pageParts" );
var pageParts = log.pageParts;
expect( pageParts ).toBeQuery();
//systemOutput( pageParts.toString(), true );
pageParts = _toPartsStruct( pageParts );

key = "ldev5206.cfc:5:5";
expect( pageParts ).toHaveKey( key );
expect( pageParts[ key ].snippet ).toBe( "sleep(5)" );

key = "ldev5206_tag.cfc:6:6";
expect( pageParts ).toHaveKey( key );
expect( pageParts[ key ].snippet ).toBe( "sleep(5)" );
});
});
}

private string function createURI(string calledName){
var baseURI="/test/#listLast(getDirectoryFromPath(getCurrentTemplatePath()),"\/")#/";
return baseURI&""&calledName;
private string function createURI( string calledName ){
var baseURI = "/test/#listLast( getDirectoryFromPath( getCurrentTemplatePath() ), "\/" )#/";
return baseURI & "" & calledName;
}

private function enableExecutionLog(class, args){
private function enableExecutionLog( string class, struct args ){
admin action="UpdateExecutionLog" type="server" password="#request.SERVERADMINPASSWORD#"
class="#arguments.class#" enabled= true
arguments=arguments.args;
Expand All @@ -51,10 +104,37 @@ component extends = "org.lucee.cfml.test.LuceeTestCase" {
admin action="PurgeDebugPool" type="server" password="#request.SERVERADMINPASSWORD#";
}

private function getDebugEntry(){
private function getLoggedDebugData(){
var logs = [];
admin action="getDebugEntry" type="server" password="#request.SERVERADMINPASSWORD#" returnVariable="logs";
admin action="getLoggedDebugData" type="server" password="#request.SERVERADMINPASSWORD#" returnVariable="logs";
return logs;
}


private function _toPartsStruct( query pageParts ){
var parts = duplicate( pageParts );
var dir = getDirectoryFromPath( getCurrentTemplatePath() ) & "/ldev5206/";
queryAddColumn( parts, "key" );
var r = 0;
loop query=parts {
var r = parts.currentrow;
// TODO currentrow required LDEV-5210
querySetCell( parts, "path", mid( parts.path[ r ], len( dir ) ), r ); // less verbose
querySetCell( parts, "key", parts.path[ r ] & ":" & parts.startLine[ r ] & ":" & parts.endLine[ r ], r );
}
var st = QueryToStruct(parts, "key");
return st;
}

function getDebugLogs() cachedwithin="request" {
disableExecutionLog();
enableExecutionLog( "lucee.runtime.engine.DebugExecutionLog",{
"unit": "milli"
//"min-time": 100
});
local.result = _InternalRequest(
template : "#uri#/ldev5206.cfm",
url: "pagePoolClear=true" // TODO cfcs aren't recompiled like cfm templates?
);
return getLoggedDebugData();
}
}
4 changes: 4 additions & 0 deletions test/tickets/LDEV5206/Application.cfc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
component {
this.name='LDEV-5206';
function onRequestStart(){
if ( structKeyExists( url, "pagePoolClear" ) )
pagePoolClear();
}
}
1 change: 1 addition & 0 deletions test/tickets/LDEV5206/ldev5206.cfc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// test DebugExecutionLog refers to this code, update if changed
component {
this.name='LDEV-5206';
function doSleep(){
Expand Down
1 change: 1 addition & 0 deletions test/tickets/LDEV5206/ldev5206.cfm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<cfscript>
// test DebugExecutionLog refers to this code, update if changed
sleep(5);
echo("back from sleep");
cfc = new ldev5206();
Expand Down
3 changes: 2 additions & 1 deletion test/tickets/LDEV5206/ldev5206_tag.cfc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<!--- test DebugExecutionLog refers to this code, update if changed --->
<cfcomponent>
<cfset this.name='LDEV-5206'>
<cfscript>
function doSleep(){
sleep(5);
}
</cfscript>
</cfcomponent>
</cfcomponent>

0 comments on commit 982c5e6

Please sign in to comment.