Skip to content

Commit

Permalink
LDEV-5053 wip test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Aug 2, 2024
1 parent a8c2bef commit 8356b2e
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 0 deletions.
119 changes: 119 additions & 0 deletions test/tickets/LDEV5053.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {

function beforeAll() {
variables.uri = createURI("LDEV5053");
if (noMysql()) return;
variables.ds = server.getDatasource("mysql");
variables.runs = 2500;
query datasource=ds {
echo("DROP TABLE IF EXISTS LDEV5053");
}
query datasource=ds{
echo("CREATE TABLE LDEV5053 ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(36))");
}
configImport( { "inspectTemplate": "once" }, "server", request.serverAdminPassword );
}

function afterAll() {
if (noMysql()) return;
query datasource=ds {
echo("DROP TABLE IF EXISTS LDEV5053");
}
}

function run( testResults , testBox ) {
describe( "test case for LDEV-5053", function() {

xit (title = "test simple", skip=noMysql(), body = function( currentSpec ) {
systemOutput("normal mode: ", true);
truncateTestTable();
var arr = [];
ArraySet( arr, 1, variables.runs, 0 );
ArrayEach( arr, function( item, idx ){
systemOutput(idx & ", ");
var result = _InternalRequest(
template : uri & "_mysql/LDEV5053_mysql.cfm",
url: {
chaos: false,
idx: arguments.idx
}
);
});
expect( getTestRowCount() ).toBe( ArrayLen( arr ) );
});

xit (title = "error in arrayEach causes cascading errors (mysql)", skip=noMysql(), body = function( currentSpec ) {
systemOutput("chaosmode: ", true);
truncateTestTable();
var arr = [];
ArraySet( arr, 1, variables.runs, 0 );
// every third call with throw an exception
ArrayEach( arr, function( item, idx ){
// systemOutput(idx & ", ");
try {
var result = _InternalRequest(
template : uri & "_mysql/LDEV5053_mysql.cfm",
url: {
chaos: true,
idx: arguments.idx
}
);
} catch ( e ) {
if ( e.message does not contain "chaos" )
rethrow;
// systemOutput(" expected chaos error at [#idx#]", true );
// ignore
}
});

expect( getTestRowCount() ).toBe( ArrayLen( arr ) );
});

it (title = "error in arrayEach causes cascading errors (qoq)", body = function( currentSpec ) {
systemOutput("chaosmode: ", true);
var arr = [];
ArraySet( arr, 1, variables.runs, 0 );
// every third call with throw an exception
ArrayEach( arr, function( item, idx ){
//systemOutput(idx & ", ");
try {
var result = _InternalRequest(
template : uri & "_qoq/LDEV5053_qoq.cfm",
url: {
chaos: true,
idx: arguments.idx
}
);
} catch ( e ) {
if ( e.message does not contain "chaos" )
rethrow;
//systemOutput(" expected chaos error at [#idx#]", true );
// ignore
}
});
});
});
}

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

private function truncateTestTable() {
query datasource=ds {
echo( "TRUNCATE TABLE ldev5053" );
}
}

private function getTestRowCount() {
query datasource=ds name="local.q" {
echo( "SELECT count(*) as r FROM ldev5053" );
}
return q.r;
}

private function noMysql(){
return (structCount( server.getDatasource("mysql") ) eq 0);
}
}
8 changes: 8 additions & 0 deletions test/tickets/LDEV5053_mysql/Application.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
component {

this.name = "LDEV5053-mysql";
this.datasources["LDEV5053"] = server.getDatasource("mysql");
// fallback datasource without the LDEV5053 table
this.datasource = server.getDatasource( "h2", server._getTempDir( "ldev5053" ) );

}
22 changes: 22 additions & 0 deletions test/tickets/LDEV5053_mysql/LDEV5053_mysql.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<cfscript>
param name="url.chaos";
param name="url.idx";
params = {
name: {value: createUUID(), sqltype="varchar" }
};
query params=params result="result" datasource="LDEV5053" {
echo( "INSERT INTO ldev5053 ( name ) VALUES ( :name )" );
}
params.id = { value: result.generatedKey, sqltype="numeric" };
query name="q" params=params datasource="LDEV5053" {
echo( "SELECT id, name FROM ldev5053 WHERE name = :name AND id = :id " );
}
if( url.chaos && (url.idx mod 3) eq 1)
throw "chaos mode, throw exception at [#url.idx#]";
if ( q.id != params.id.value || q.name != params.name.value || q.recordcount !=1 )
throw "invalid result [#params.toJson()#], [#q.toJson()#]";
</cfscript>
7 changes: 7 additions & 0 deletions test/tickets/LDEV5053_qoq/Application.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
component {

this.name = "LDEV5053-qoq";
// fallback datasource without the LDEV5053 table
this.datasource = server.getDatasource( "mysql" );

}
28 changes: 28 additions & 0 deletions test/tickets/LDEV5053_qoq/LDEV5053_qoq.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<cfscript>
param name="url.chaos";
param name="url.idx";
ldev5053_qoq = queryNew( "id,name,data", "integer,varchar,varchar" );
names= [ 'micha', 'zac', 'brad', 'pothys', 'gert' ];
loop array="#names#" item="n" {
r = queryAddRow( ldev5053_qoq );
querySetCell( ldev5053_qoq, "id", r, r );
querySetCell( ldev5053_qoq, "name", n, r );
}
sql = "SELECT id, name FROM ldev5053_qoq ORDER BY name";
if( url.chaos && ( url.idx mod 3) eq 1 ){
sql = "BAD " & sql;
}
// native engine
q_native = QueryExecute(
sql = sql,
options = { dbtype: 'query' }
);
if( url.chaos && ( url.idx mod 3) eq 1 ){
sleep( 10 );
throw "chaos mode, throw exception at [#url.idx#]";
}
</cfscript>

0 comments on commit 8356b2e

Please sign in to comment.