From 8356b2ea4049336bc825756f88dda3e6aa9de3f0 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Fri, 2 Aug 2024 12:47:21 +0200 Subject: [PATCH] LDEV-5053 wip test case --- test/tickets/LDEV5053.cfc | 119 ++++++++++++++++++ test/tickets/LDEV5053_mysql/Application.cfc | 8 ++ .../tickets/LDEV5053_mysql/LDEV5053_mysql.cfm | 22 ++++ test/tickets/LDEV5053_qoq/Application.cfc | 7 ++ test/tickets/LDEV5053_qoq/LDEV5053_qoq.cfm | 28 +++++ 5 files changed, 184 insertions(+) create mode 100644 test/tickets/LDEV5053.cfc create mode 100644 test/tickets/LDEV5053_mysql/Application.cfc create mode 100644 test/tickets/LDEV5053_mysql/LDEV5053_mysql.cfm create mode 100644 test/tickets/LDEV5053_qoq/Application.cfc create mode 100644 test/tickets/LDEV5053_qoq/LDEV5053_qoq.cfm diff --git a/test/tickets/LDEV5053.cfc b/test/tickets/LDEV5053.cfc new file mode 100644 index 0000000000..daad04e9f1 --- /dev/null +++ b/test/tickets/LDEV5053.cfc @@ -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); + } +} \ No newline at end of file diff --git a/test/tickets/LDEV5053_mysql/Application.cfc b/test/tickets/LDEV5053_mysql/Application.cfc new file mode 100644 index 0000000000..d596dad9f8 --- /dev/null +++ b/test/tickets/LDEV5053_mysql/Application.cfc @@ -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" ) ); + +} diff --git a/test/tickets/LDEV5053_mysql/LDEV5053_mysql.cfm b/test/tickets/LDEV5053_mysql/LDEV5053_mysql.cfm new file mode 100644 index 0000000000..9388c8790e --- /dev/null +++ b/test/tickets/LDEV5053_mysql/LDEV5053_mysql.cfm @@ -0,0 +1,22 @@ + + 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()#]"; + \ No newline at end of file diff --git a/test/tickets/LDEV5053_qoq/Application.cfc b/test/tickets/LDEV5053_qoq/Application.cfc new file mode 100644 index 0000000000..ca613eb18d --- /dev/null +++ b/test/tickets/LDEV5053_qoq/Application.cfc @@ -0,0 +1,7 @@ +component { + + this.name = "LDEV5053-qoq"; + // fallback datasource without the LDEV5053 table + this.datasource = server.getDatasource( "mysql" ); + +} diff --git a/test/tickets/LDEV5053_qoq/LDEV5053_qoq.cfm b/test/tickets/LDEV5053_qoq/LDEV5053_qoq.cfm new file mode 100644 index 0000000000..3af4e0dc04 --- /dev/null +++ b/test/tickets/LDEV5053_qoq/LDEV5053_qoq.cfm @@ -0,0 +1,28 @@ + + 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#]"; + } + \ No newline at end of file