twister

HTTP fault injector for testing
Log | Files | Refs | README | LICENSE

test_chaos.sh (1847B)


      1 #!/bin/sh
      2 
      3 # This file is part of GNUnet.
      4 # Copyright (C) 2018 Taler Systems SA
      5 # 
      6 # Twister is free software; you can redistribute it and/or
      7 # modify it under the terms of the GNU General Public License
      8 # as published by the Free Software Foundation; either version
      9 # 3, or (at your option) any later version.
     10 # 
     11 # Twister is distributed in the hope that it will be useful,
     12 # but WITHOUT ANY WARRANTY; without even the implied warranty
     13 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     14 # the GNU General Public License for more details.
     15 # 
     16 # You should have received a copy of the GNU General Public
     17 # License along with Twister; see the file COPYING.  If not,
     18 # write to the Free Software Foundation, Inc., 51 Franklin
     19 # Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 
     21 # @author Marcello Stanisci
     22 # @author Christian Grothoff
     23 # 
     24 # @file test_twister.sh
     25 # 
     26 # @brief Twister testcases, with a 5% chaos probability (#5737).
     27 
     28 
     29 if ! which curl > /dev/null
     30 then
     31     echo "curl not found";
     32     exit 77
     33 fi
     34 
     35 TWISTER_URL_V4="http://localhost:8888/"
     36 TWISTER_URL="http://[::1]:8888/"
     37 
     38 # Launch the Web server.
     39 ./test_twister_webserver &
     40 web_server_pid=$!
     41 
     42 echo Webserver launched.
     43 
     44 # Launch the Twister.
     45 taler-twister-service -c ./test_chaos.conf &
     46 twister_service_pid=$!
     47 
     48 echo "Twister chaos'd launched (${twister_service_pid})."
     49 
     50 # We give 100 rounds to match a 5% probability.
     51 for i in $(seq 1 100); do
     52   status_code=$(curl -s ${TWISTER_URL_V4} -o /dev/null \
     53     -w "%{http_code}")
     54   
     55   # check status code was hacked
     56   if test 503 = $status_code; then
     57     echo "$i-th round: found 'Service Unavailable'; success."
     58     kill $web_server_pid
     59     kill $twister_service_pid
     60     exit 0
     61   fi
     62 done
     63 
     64 echo Could not find 'Service Unavailable response; fail!'
     65 # shutdown twister and webserver
     66 kill $web_server_pid
     67 kill $twister_service_pid
     68 
     69 exit 1