summaryrefslogtreecommitdiffstats
path: root/test/lock-device/success/test.sh
blob: cf8a42c0436fb8370253294130e6307467c38a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#
# Copyright (C) 2020 Bell Canada.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

CBA_NAME="lock-device"
TEST_NAME="success"
TEST_NUMBER=$RANDOM
mkdir -p "$RESPONSES_DIRECTORY/$CBA_NAME/$TEST_NAME/$TEST_NUMBER/"

. ./$TEST_DIRECTORY/utils.sh

echo "Running test: $CBA_NAME:$TEST_NUMBER:$TEST_NAME"


# Request 1: Acquire lock and run for 30 sec
# Sleep 5 - ensure req 1 is processed before req 2
# Request 2: Wait for lock 10 sec then time out
# Sleep 60 - lock should have been released after this time
# Request 3: Acquire lock and run for 30 sec
# Sleep 5 - ensure req 3 is processed before req 4
# Request 4: Wait for lock 10 sec then time out
delays=(0 5 60 5 0)

for i in `seq 1 4`
do
    echo "Sending request $i"
    RESPONSE_HEADERS_FILE="$RESPONSES_DIRECTORY/$CBA_NAME/$TEST_NAME/$TEST_NUMBER/response-headers-$i"
    RESPONSE_PAYLOAD_FILE="$RESPONSES_DIRECTORY/$CBA_NAME/$TEST_NAME/$TEST_NUMBER/response-payload-$i"
    REQUEST_PAYLOAD_FILE="$TEST_DIRECTORY/$CBA_NAME/$TEST_NAME/request-payloads/request-payload-$i.json"

    process_cba $REQUEST_PAYLOAD_FILE $RESPONSE_PAYLOAD_FILE $RESPONSE_HEADERS_FILE &
    pids[${i}]=$!
    sleep ${delays[$i]}
done

echo "Waiting for responses - pids: ${pids[*]}"
for pid in ${pids[*]}
do
    echo "Waiting for pid $pid"
    wait $pid
done

for i in `seq 1 4`
do
    echo "Assert payload - request $i"
    RESPONSE_PAYLOAD_FILE="$RESPONSES_DIRECTORY/$CBA_NAME/$TEST_NAME/$TEST_NUMBER/response-payload-$i"
    EXPECTED_PAYLOAD_FILE="$TEST_DIRECTORY/$CBA_NAME/$TEST_NAME/expected-payloads/expected-payload-$i.json"
    assert_cds_response_equals $EXPECTED_PAYLOAD_FILE $RESPONSE_PAYLOAD_FILE
done