Skip to content

Commit

Permalink
chore: improve performance and readability
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 authored May 30, 2024
1 parent fe7478b commit 63e74d6
Show file tree
Hide file tree
Showing 44 changed files with 1,114 additions and 1,184 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ start-mirror-server:
cp ./apache-jmeter-5.6.3/lib/log4j-core-2.22.1.jar ./apache-jmeter-5.6.3/lib/log4j-core-2.11.1.jar
cp ./apache-jmeter-5.6.3/lib/log4j-1.2-api-2.22.1.jar ./apache-jmeter-5.6.3/lib/log4j-1.2-api-2.11.1.jar
echo "Starting the mirror server on port 8500."

./apache-jmeter-5.6.3/bin/mirror-server --port 8500 &

test:
Expand Down
129 changes: 19 additions & 110 deletions integration/001_extensions-enable-all.jmx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<stringProp name="Argument.desc">HTTP path for the raw.githubusercontent.com repo</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="config_path" elementType="Argument">
<stringProp name="Argument.name">config_path</stringProp>
<stringProp name="Argument.value">${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</Arguments>
<hashTree/>
Expand Down Expand Up @@ -131,31 +136,9 @@
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="Extract extension IDs" enabled="true">
<stringProp name="scriptLanguage">javascript</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="filename">${config_path}/scripts/extract_extensions_ids.js</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">var resp = JSON.parse(prev.getResponseDataAsString());
var excludedExtensions = (vars.get(&quot;excludedExtensions&quot;) || &quot;&quot;).split(&quot;,&quot;);

var extensions = {};

for (var i = 0; i &lt; resp.extensions.length; i++) {
var ext = resp.extensions[i];
if (excludedExtensions.indexOf(ext.id) === -1) {
extensions[ext.id] = true;
}
}



extensionList = Object.keys(extensions);
//extensionList[1] = &apos;nostrmarket&apos;
//extensionList.length = 3
vars.put(&quot;extensions&quot;, extensionList);



vars.put(&quot;extensionsLength&quot;, extensionList.length);
</stringProp>
<stringProp name="script"></stringProp>
</JSR223PostProcessor>
<hashTree/>
</hashTree>
Expand Down Expand Up @@ -536,13 +519,9 @@ vars.put(&quot;extensionsLength&quot;, extensionList.length);
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Extract extension data" enabled="true">
<stringProp name="scriptLanguage">javascript</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="filename">${config_path}/scripts/extract_extension_data.js</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">var extensions = vars.get(&quot;extensions&quot;)
var extensionIndex = vars.get(&quot;extensionIndex&quot;)

vars.put(&quot;extension&quot;, extensions.split(&quot;,&quot;)[extensionIndex - 1])
</stringProp>
<stringProp name="script"></stringProp>
</JSR223Sampler>
<hashTree/>
<ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="Install Extension Module" enabled="true">
Expand Down Expand Up @@ -659,20 +638,9 @@ vars.put(&quot;extension&quot;, extensions.split(&quot;,&quot;)[extensionIndex -
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Extract extension data " enabled="true">
<stringProp name="scriptLanguage">javascript</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="filename">${config_path}/scripts/extract_extension_data.js</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">var extensions = vars.get(&quot;extensions&quot;)
var adminExtensions = vars.get(&quot;adminExtensions&quot;)
var extensionIndex = vars.get(&quot;extensionIndex&quot;)
var extesion = extensions.split(&quot;,&quot;)[extensionIndex - 1]
var isAdminExtension = adminExtensions.split(&quot;,&quot;).indexOf(extesion) !== -1

vars.put(&quot;extension&quot;, extesion)
vars.put(&quot;isAdminExtension&quot;, isAdminExtension)

var responseCode = prev.getResponseCode()

vars.put(&quot;responseCode&quot;, responseCode)</stringProp>
<stringProp name="script"></stringProp>
</JSR223Sampler>
<hashTree/>
<DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="Debug Sampler" enabled="true">
Expand Down Expand Up @@ -854,13 +822,9 @@ vars.put(&quot;responseCode&quot;, responseCode)</stringProp>
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="Extract extension data " enabled="true">
<stringProp name="scriptLanguage">javascript</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="filename">${config_path}/scripts/extract_extension_data.js</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">var extensions = vars.get(&quot;extensions&quot;)
var extensionIndex = vars.get(&quot;extensionIndex&quot;)

vars.put(&quot;extension&quot;, extensions.split(&quot;,&quot;)[extensionIndex - 1])
</stringProp>
<stringProp name="script"></stringProp>
</JSR223Sampler>
<hashTree/>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="[${extension}] Uninstall extension" enabled="true">
Expand Down Expand Up @@ -1156,18 +1120,9 @@ vars.put(&quot;extension&quot;, extensions.split(&quot;,&quot;)[extensionIndex -
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="Extract latest release" enabled="true">
<stringProp name="scriptLanguage">javascript</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="filename">${config_path}/scripts/extract_latest_extension_release.js</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">var resp = JSON.parse(prev.getResponseDataAsString())
var latestRelease = resp[resp.length - 1]

var ext_id = vars.get(&quot;extension&quot;)

vars.put(&quot;ext_id&quot;, ext_id)
vars.put(&quot;archive&quot;, latestRelease.archive)
vars.put(&quot;source_repo&quot;, latestRelease.source_repo)
vars.put(&quot;version&quot;, latestRelease.version)
</stringProp>
<stringProp name="script"></stringProp>
</JSR223PostProcessor>
<hashTree/>
</hashTree>
Expand Down Expand Up @@ -1628,27 +1583,9 @@ vars.put(&quot;version&quot;, latestRelease.version)
<JSR223Assertion guiclass="TestBeanGUI" testclass="JSR223Assertion" testname="Check Status Code 200 (or 401 for admin extension)" enabled="true">
<stringProp name="scriptLanguage">javascript</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="filename">${config_path}/scripts/check_admin_extension_status_code.js</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">var responseCode = +prev.getResponseCode()
var isAdminExtension = vars.get(&quot;isAdminExtension&quot;)


if (isAdminExtension === &apos;true&apos;) {
if (responseCode !== 200 &amp;&amp; responseCode !== 401) {
AssertionResult.setFailureMessage(
&quot;Expected response code 200 for 401 for admin extension but got: &quot; +
responseCode
);
AssertionResult.setFailure(true);
}
} else if (responseCode !== 200) {
AssertionResult.setFailureMessage(
&quot;Expected response code 200 but got: &quot; + responseCode
);
AssertionResult.setFailure(true);
}
</stringProp>
<stringProp name="script"> </stringProp>
</JSR223Assertion>
<hashTree/>
</hashTree>
Expand Down Expand Up @@ -1726,11 +1663,6 @@ if (isAdminExtension === &apos;true&apos;) {
<intProp name="Assertion.test_type">8</intProp>
</ResponseAssertion>
<hashTree/>
<ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Wait a bit" enabled="false">
<stringProp name="ConstantTimer.delay">3000</stringProp>
<stringProp name="TestPlan.comments">for the callback to be invoked</stringProp>
</ConstantTimer>
<hashTree/>
</hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="[${extension}] Go to extension page (disabled)" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
Expand Down Expand Up @@ -1877,11 +1809,6 @@ if (isAdminExtension === &apos;true&apos;) {
<intProp name="Assertion.test_type">8</intProp>
</ResponseAssertion>
<hashTree/>
<ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Wait a bit" enabled="false">
<stringProp name="ConstantTimer.delay">3000</stringProp>
<stringProp name="TestPlan.comments">for the callback to be invoked</stringProp>
</ConstantTimer>
<hashTree/>
</hashTree>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="[${extension}] Go to extension page (enabled)" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
Expand Down Expand Up @@ -1946,27 +1873,9 @@ if (isAdminExtension === &apos;true&apos;) {
<JSR223Assertion guiclass="TestBeanGUI" testclass="JSR223Assertion" testname="Check Status Code 200 (or 401 for admin extension)" enabled="true">
<stringProp name="scriptLanguage">javascript</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="filename">${config_path}/scripts/check_admin_extension_status_code.js</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">var responseCode = +prev.getResponseCode()
var isAdminExtension = vars.get(&quot;isAdminExtension&quot;)


if (isAdminExtension === &quot;true&quot;) {
if (responseCode !== 200 &amp;&amp; responseCode !== 401) {
AssertionResult.setFailureMessage(
&quot;Expected response code 200 for 401 for admin extension but got: &quot; +
responseCode
);
AssertionResult.setFailure(true);
}
} else if (responseCode !== 200) {
AssertionResult.setFailureMessage(
&quot;Expected response code 200 but got: &quot; + responseCode
);
AssertionResult.setFailure(true);
}
</stringProp>
<stringProp name="script"></stringProp>
</JSR223Assertion>
<hashTree/>
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Check Status Code 200" enabled="true">
Expand Down
Loading

0 comments on commit 63e74d6

Please sign in to comment.