xref: /aosp_15_r20/external/protobuf/php/tests/multirequest.sh (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1#!/bin/bash
2
3cd $(dirname $0)
4
5set -e
6
7PORT=12345
8TIMEOUT=10
9
10./compile_extension.sh
11
12run_test() {
13  echo
14  echo "Running multirequest test, args: $@"
15
16  RUN_UNDER=""
17  EXTRA_ARGS=""
18  ARGS="-d xdebug.profiler_enable=0 -d display_errors=on -dextension=../ext/google/protobuf/modules/protobuf.so"
19
20  for i in "$@"; do
21    case $i in
22      --valgrind)
23        RUN_UNDER="valgrind --error-exitcode=1"
24        shift
25        ;;
26      --keep_descriptors)
27        EXTRA_ARGS=-dprotobuf.keep_descriptor_pool_after_request=1
28        shift
29        ;;
30    esac
31  done
32
33  export ZEND_DONT_UNLOAD_MODULES=1
34  export USE_ZEND_ALLOC=0
35  rm -f nohup.out
36  nohup $RUN_UNDER php $ARGS $EXTRA_ARGS -S localhost:$PORT multirequest.php >nohup.out 2>&1 &
37  PID=$!
38
39  if ! timeout $TIMEOUT bash -c "until echo > /dev/tcp/localhost/$PORT; do sleep 0.1; done" > /dev/null 2>&1; then
40    echo "Server failed to come up after $TIMEOUT seconds"
41    cat nohup.out
42    exit 1
43  fi
44
45  seq 2 | xargs -I{} wget -nv http://localhost:$PORT/multirequest.result -O multirequest{}.result
46  REQUESTS_SUCCEEDED=$?
47
48
49  if kill $PID > /dev/null 2>&1 && [[ $REQUESTS_SUCCEEDED == "0" ]]; then
50    wait
51    echo "Multirequest test SUCCEEDED"
52  else
53    echo "Multirequest test FAILED"
54    cat nohup.out
55    exit 1
56  fi
57}
58
59run_test
60run_test --keep_descriptors
61run_test --valgrind
62run_test --valgrind --keep_descriptors
63