Skip to content

Commit

Permalink
Merge pull request #275 from Cognifide/feature/aet-client-sh
Browse files Browse the repository at this point in the history
update aet.sh with new options
  • Loading branch information
Skejven authored Jul 2, 2018
2 parents 65cb24d + 74e911a commit f09b160
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 30 deletions.
8 changes: 6 additions & 2 deletions client/client-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ AET Test executor
Usage:
./aet.sh <endpoint> [<suite_file_name>] [-i | --interval <POLL_INTERVAL>]
./aet.sh <endpoint> [<suite_file_name>] [options]
Options:
-i --interval <POLL_INTERVAL> - Set interval in seconds for polling suite status. Default interval : 1 sec
-d --domain <DOMAIN> - Override domain attribute defined in suite file
-c --correlationId <CORRELATION_ID> - Set id of patterns to run test against
-i --interval <POLL_INTERVAL> - Set interval in seconds for polling suite status. Default interval : 1 sec
-w --waitForUnlock <TIMEOUT> - Set timeout for the script to wait for unlocked suite. Default timeout: 0 sec
-v --verbose - Make it more descriptive
```

### Prerequisites
Expand Down
99 changes: 74 additions & 25 deletions client/client-scripts/aet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@
#

POLL_INTERVAL=1
UNLOCK_TIMEOUT=0
SUITE_ENDPOINT="/suite"
DOMAIN_BODY=""
CORRELATION_ID_BODY=""
function usage {
echo
echo "AET Test executor"
echo
echo "Usage:"
echo
echo -e "\t$0 <endpoint> [<suite_file_name>] [-i | --interval <POLL_INTERVAL>]"
echo -e "\t$0 <endpoint> [<suite_file_name>] [options]"
echo
echo "Options:"
echo -e "\t-i --interval <POLL_INTERVAL> - Set interval in seconds for polling suite status. Default interval : 1 sec"
echo -e "\t-d --domain <DOMAIN> - Override domain attribute defined in suite file"
echo -e "\t-c --correlationId <CORRELATION_ID> - Set id of patterns to run test against."
echo -e "\t-i --interval <POLL_INTERVAL> - Set interval in seconds for polling suite status. Default interval : 1 sec."
echo -e "\t-w --waitForUnlock <TIMEOUT> - Set timeout for the script to wait for unlocked suite. Default timeout: 0 sec."
echo -e "\t-v --verbose - Make it more descriptive"
echo
exit 1
}
Expand All @@ -43,7 +50,10 @@ function extract_code_and_body {
# download xUnit report
function parse_xunit {
curl $1 --output xUnit.xml --silent
test_failures=$(xmllint --xpath 'string(//testsuites/@failures)' xUnit.xml)
all_run_test=$(xmllint --xpath 'string(//testsuites/@tests)' xUnit.xml)
if ((all_run_test > 0)); then
test_failures=$(xmllint --xpath 'string(//testsuites/@failures)' xUnit.xml)
fi
}

# prepare html file with redirect to AET results report
Expand All @@ -60,6 +70,35 @@ function prepare_redirect {
</html>" > redirect.html
}

function process_locked_suite {
if [[ $code -eq 500 && UNLOCK_TIMEOUT -gt 0 && "$body" =~ "Suite is currently locked" ]]; then
echo "Waiting for suite to be unlocked for $UNLOCK_TIMEOUT second(s)"
sleep $(( 5 > $UNLOCK_TIMEOUT ? $UNLOCK_TIMEOUT : 5))
((UNLOCK_TIMEOUT-=5))
start_suite
else
echo "Unsuccessful Request to \"$endpoint$SUITE_ENDPOINT\", status: $code
$body"
exit 1
fi
}

# request /suite endpoint
function start_suite {
run_response=$(curl -sw "%{http_code}" -F "suite=@$suite_file_name"$DOMAIN_BODY$CORRELATION_ID_BODY "$endpoint$SUITE_ENDPOINT")
extract_code_and_body "$run_response"

if [ $code -eq 200 ]; then
correlation_id=$(echo $body | jq -r ".correlationId")
status_url=$(echo $body | jq -r ".statusUrl")
html_report_url=$(echo $body | jq -r ".htmlReportUrl")
xunit_url=$(echo $body | jq -r ".xunitReportUrl")
echo "Suite started with correlation id: $correlation_id"
else
process_locked_suite
fi
}

[[ $# -eq 0 ]] && usage

endpoint=$1
Expand All @@ -71,36 +110,48 @@ while [[ $# -gt 0 ]]; do
POLL_INTERVAL="$2"
shift 2
;;
-w | --waitForUnlock )
UNLOCK_TIMEOUT="$2"
shift 2
;;
-d | --domain )
DOMAIN="$2"
DOMAIN_BODY=" -F domain=$DOMAIN"
shift 2
;;
-c | --correlationId )
CORRELATION_ID=$2
CORRELATION_ID_BODY=" -F pattern=$CORRELATION_ID"
shift 2
;;
-v | --verbose )
VERBOSE=1
shift 1
;;
* )
shift
;;
esac
done

# request /suite endpoint
run_response=$(curl -sw "%{http_code}" -F "suite=@$suite_file_name" "$endpoint$SUITE_ENDPOINT")
extract_code_and_body "$run_response"

if [ $code -eq 200 ]; then
correlation_id=$(echo $body | jq -r ".correlationId")
status_url=$(echo $body | jq -r ".statusUrl")
html_report_url=$(echo $body | jq -r ".htmlReportUrl")
xunit_url=$(echo $body | jq -r ".xunitReportUrl")
echo "Suite started with correlation id: $correlation_id"
else
echo "Unsuccessful Request to \"$endpoint$SUITE_ENDPOINT\", status: $code
$body"
exit 1
if [[ $VERBOSE -eq 1 ]]; then
echo -e "Test parameters:"
echo -e "\tAET endpoint: $endpoint$SUITE_ENDPOINT"
echo -e "\tSuite: $suite_file_name"
echo -e "\tOverridden domain: ${DOMAIN-not set}"
echo -e "\tPattern id: ${CORRELATION_ID-not set}"
echo ""
fi

start_suite

# request /status/<correlationId> endpoint
process_status=true
last_progress_message=""
while $process_status; do
status_response=$(curl -sw "%{http_code}" $endpoint$status_url)
extract_code_and_body "$status_response"

if [ $code -eq 200 ]; then
if [ $code -eq 200 ]; then
status=$(echo $body | jq -r ".status")
message=$(echo $body | jq -r ".message")

Expand All @@ -110,24 +161,22 @@ while $process_status; do
parse_xunit "$endpoint$xunit_url"
prepare_redirect "$html_report_url"
echo -e "$message\nReport url:\n$html_report_url"
echo "Test failures: $test_failures"
echo "Test failures: ${test_failures:=1}"
exit $test_failures
;;
"PROGRESS")
last_progress_message=$message
"ERROR"|"PROGRESS")
echo "$message"
;;
"ERROR"|"FATAL_ERROR")
"FATAL_ERROR")
echo "$message"
exit 1
;;
*)
echo "$last_progress_message"
;;
esac
sleep $POLL_INTERVAL
else
echo "Unsuccessful Request to \"$endpoint$status_url\", status: $code
echo "Unsuccessful status request to \"$endpoint$status_url\", status: $code
$body"
exit 1
fi
Expand Down
19 changes: 16 additions & 3 deletions documentation/src/main/wiki/ClientScripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ Usage:
./aet.sh <endpoint> [<suite_file_name>] [-i | --interval <POLL_INTERVAL>]
Options:
-i --interval <POLL_INTERVAL> - Set interval in seconds for polling suite status. Default interval : 1 sec
-d --domain <DOMAIN> - Override domain attribute defined in suite file
-c --correlationId <CORRELATION_ID> - Set id of patterns to run test against
-i --interval <POLL_INTERVAL> - Set interval in seconds for polling suite status. Default interval : 1 sec
-w --waitForUnlock <TIMEOUT> - Set timeout for the script to wait for unlocked suite. Default timeout: 0 sec
-v --verbose - Make it more descriptive
```

The shell script needs one parameter to trigger tests. Set the `endpoint` parameter to point the script to a domain which exposes the [[Test Executor API|TestExecutor]].
Expand All @@ -26,7 +30,11 @@ The shell script can be run with parameters which are described below:
| --------- | ----------- | ------------- | --------- |
| `endpointDomain` | an AET domain which exposes the [[Test Executor API\|TestExecutor]] | - | yes |
| `suite_file_name` | a full path to the suite definition file (at least a file name with an extension is required, e.g. `testSuite.xml`). | suite.xml | no |
| `-d \| --domain <DOMAIN>` | overrides the _domain_ parameter value from the test suite definition. | - | no |
| `-c \| --correlationId <CORRELATION_ID>` | Id of suite that will be used as patterns source. Identical structure of pattern and current suites is assumed. | - | no |
| `-i \| --interval <POLL_INTERVAL>` | an interval of polling the status of the test currently executed. (Unit: seconds) | 1 | no |
| `-w \| --waitForUnlock <TIMEOUT>` | specify the time that the script will wait for the suite to be unlocked. (Unit: seconds) | 0 | no |
| `-v \| --verbose` | if provided additional information about execution is printed out | - | no |

#### Exit status

Expand All @@ -43,7 +51,7 @@ During test execution the script creates two files:
In order to run properly, following commands need to be available on the PATH of the environment the script is executed on:
* `curl` - used to make an actual request against the [[Test Executor API|TestExecutor]] and also to download the `xUnit.xml` file after the test has reached completion. It comes preinstalled on most Unix systems. [Download link](https://curl.haxx.se/download.html)
* `jq` - used to parse JSON responses from the [[Test Executor API|TestExecutor]]. [Download link](https://stedolan.github.io/jq/download/)
* `xmllint` - used to retirieve failure information from the downloaded `xUnit.xml`. It comes preinstalled on most Unix systems. For Windows installation instructions, refer to [Jo Jordan's post](http://flowingmotion.jojordan.org/2011/10/08/3-steps-to-download-xmllint/).
* `xmllint` - used to retrieve failure information from the downloaded `xUnit.xml`. It comes preinstalled on most Unix systems. For Windows installation instructions, refer to [Jo Jordan's post](http://flowingmotion.jojordan.org/2011/10/08/3-steps-to-download-xmllint/).

#### Example usages

Expand All @@ -59,5 +67,10 @@ Execute a test as above, suite configuration is available in the `my-suite.xml`

Execute a test as above, poll the status of running the test every 5 seconds.
```
./aet.sh http://localhost:8181 my-suite.xml 5
./aet.sh http://localhost:8181 my-suite.xml -i 5
```

Execute a test as above, override domain and wait for suite to be unlocked for 5 minutes at most
```
./aet.sh http://localhost:8181 my-suite.xml -i 5 -d http://my.overriden.domain -w 300
```

0 comments on commit f09b160

Please sign in to comment.