forked from lucee/Lucee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ) ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |