Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.59 KB | None | 0 0
  1. --- parity-test.sh.orig 2019-04-02 12:20:52.084782728 +0200
  2. +++ parity-test.sh      2019-04-02 12:20:25.500673565 +0200
  3. @@ -1,26 +1,27 @@
  4.  #!/bin/bash
  5.  #
  6.  # Test Parity RPC - Brad Dameron (serpent6877@hotmail.com)
  7. +# Modified by https://github.com/c0deright
  8.  #
  9. -# parity-test.sh <RPC PORT> <# requests before delay> <Delay time between tests>
  10. +# parity-test.sh <HOST>:<RPC PORT> <# requests before delay> <Delay time between tests>
  11.  # Use CTRL+C to exit program
  12.  #
  13. -# Example ./parity-test.sh 8545 1000 15 5
  14. -# Test port 8545 with 1000 requests of each type 15 times with a 5 second delay between tests
  15. +# Example ./parity-test.sh localhost:8545 1000 15 5
  16. +# Test localhost on port 8545 with 1000 requests of each type 15 times with a 5 second delay between tests
  17.  #
  18.  # Requires parallel installed.
  19.  
  20.  
  21. -PORT=$1
  22. +HOST_N_PORT=$1
  23.  REQUESTS=$2
  24.  TESTS=$3
  25.  DELAY=$4
  26.  LOGFILE=parity-test.log
  27.  
  28.  # Set some defaults if no command line option
  29. -if [ -z $PORT ]
  30. +if [ -z $HOST_N_PORT ]
  31.  then
  32. -  PORT=8545
  33. +  HOST_N_PORT="localhost:8545"
  34.  fi
  35.  if [ -z $DELAY ]
  36.  then
  37. @@ -36,30 +37,31 @@
  38.  fi
  39.  
  40.  getBalance() {
  41. -   PORT=$1
  42. -   LOGFILE=$2
  43. +   HOST_N_PORT=$1
  44.     # Test getBalance
  45. -   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":1}' -H "Content-Type: application/json" -X POST localhost:$PORT >> $LOGFILE
  46. +   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":1}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  47.     # Test getWork
  48. -   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getWork","params":[],"id":73}' -H "Content-Type: application/json" -X POST localhost:$PORT >> $LOGFILE
  49. +#   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getWork","params":[],"id":73}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  50.     # Test current blockNumber
  51. -   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" -X POST localhost:$PORT >> $LOGFILE
  52. +   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  53.     # Test peerCount
  54. -   curl -s -X POST --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":74}' -H "Content-Type: application/json" -X POST localhost:$PORT >> $LOGFILE
  55. +   curl -s -X POST --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":74}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  56.     # Test accounts
  57. -   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' -H "Content-Type: application/json" -X POST localhost:$PORT >> $LOGFILE
  58. +   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  59.  }
  60.  
  61.  export -f getBalance
  62.  
  63. -for run in $(eval echo "{1..$TESTS}")
  64. +exec > >(tee -a $LOGFILE) 2>&1
  65. +
  66. +for run in $(seq $TESTS)
  67.  do
  68.     START=$(date +%s)
  69. -   echo "$START - Starting testing ---------" >> $LOGFILE
  70. -   seq $REQUESTS | parallel -j0 -N0 getBalance $PORT $LOGFILE > /dev/null
  71. +   echo "$START - Starting testing ---------"
  72. +   seq $REQUESTS | parallel -j0 -N0 getBalance $HOST_N_PORT >/dev/null
  73.     END=$(date +%s)
  74.     DIFF=$(( $END - $START ))
  75. -   echo "$END - Stopping testing ---------" >> $LOGFILE
  76. +   echo "$END - Stopping testing ---------"
  77.     echo "It took $DIFF seconds for $REQUESTS requests"
  78.     echo "Delaying for $DELAY seconds."
  79.     sleep $DELAY
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement