From e72ec5cd52706c28e8dfb523f3ba198358d3233b Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Fri, 10 Nov 2023 11:20:03 +0100 Subject: [PATCH] add support for parallel test cases and example implementation --- .../config/component/ComponentFactory.java | 1 + .../lucee/cfml/test/LuceeTestCaseParallel.cfc | 33 +++++++++++++++++++ loader/build.xml | 2 +- loader/pom.xml | 2 +- test/functions/xmlNew.cfc | 4 +-- 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 core/src/main/java/resource/component/org/lucee/cfml/test/LuceeTestCaseParallel.cfc diff --git a/core/src/main/java/lucee/runtime/config/component/ComponentFactory.java b/core/src/main/java/lucee/runtime/config/component/ComponentFactory.java index 9fbaed2097..735454895c 100644 --- a/core/src/main/java/lucee/runtime/config/component/ComponentFactory.java +++ b/core/src/main/java/lucee/runtime/config/component/ComponentFactory.java @@ -61,6 +61,7 @@ public static void deploy(Resource dir, boolean doNew) { deploy(testDir, testPath, doNew, "LuceeTestSuite"); deploy(testDir, testPath, doNew, "LuceeTestSuiteRunner"); deploy(testDir, testPath, doNew, "LuceeTestCase"); + deploy(testDir, testPath, doNew, "LuceeTestCaseParallel"); } } diff --git a/core/src/main/java/resource/component/org/lucee/cfml/test/LuceeTestCaseParallel.cfc b/core/src/main/java/resource/component/org/lucee/cfml/test/LuceeTestCaseParallel.cfc new file mode 100644 index 0000000000..70d8b6b074 --- /dev/null +++ b/core/src/main/java/resource/component/org/lucee/cfml/test/LuceeTestCaseParallel.cfc @@ -0,0 +1,33 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" { + + + private function parallel(title, threadCount=1, repetitition=1, body) { + if(arguments.threadcount<1 || arguments.threadcount>1000) { + throw "thread count need to be a number between 1 and 1000, now it is [#arguments.threadcount#]"; + } + if(arguments.repetitition<1 || arguments.repetitition>1000) { + throw "repetitition need to be a number between 1 and 1000, now it is [#arguments.repetitition#]"; + } + if(arguments.threadcount==1 || arguments.repetitition==1) { + throw "repetitition or thread count need to be bigger than 1"; + } + var prefix=createUniqueID(); + var exceptions = []; + for (var i = 1; i <= arguments.repetitition; i++) { + var names = []; + for (var y = 1; y <= arguments.threadcount; y++) { + var name="testThread-#prefix#:#i#:#y#"; + arrayAppend(names, name); + thread action="run" name=name title=arguments.title body=arguments.body exceptions=exceptions { + try { + it(title,body); + } + catch(e) { + arrayAppend(exceptions, e); + } + } + } + thread action="join" name=arrayToList(names); + } + } +} \ No newline at end of file diff --git a/loader/build.xml b/loader/build.xml index ae7d00aab5..4c3f37a840 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 00e0d957de..34262fb7bf 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.0.1.22-SNAPSHOT + 6.0.1.23-SNAPSHOT jar Lucee Loader Build diff --git a/test/functions/xmlNew.cfc b/test/functions/xmlNew.cfc index b3269f44e4..3aad743bb8 100644 --- a/test/functions/xmlNew.cfc +++ b/test/functions/xmlNew.cfc @@ -1,7 +1,7 @@ -component extends="org.lucee.cfml.test.LuceeTestCase" { +component extends="org.lucee.cfml.test.LuceeTestCaseParallel" { function run( testResults , testBox ) { describe( title = "Testcase for xmlNew() function", body = function() { - it( title = "checking xmlNew() function", body = function( currentSpec ) { + parallel( title = "checking xmlNew() function",threadCount=5, repetitition=2, body = function( currentSpec ) { var XmlDocument = xmlNew(); XMLDocument.XmlRoot = "element";