Created
January 25, 2022 14:58
-
-
Save ants/e39dadf0ec34bdccb7691aabfd42f78c to your computer and use it in GitHub Desktop.
Cert hang reproduce scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PID=$1 | |
function curtime() { | |
date "+[%H:%M:%S]" | |
} | |
function check() { | |
curl -vk https://localhost:8008/ 2>&1 | grep -q $1 | |
return $? | |
} | |
while true; do | |
echo "$(curtime) Swapping to cert 2" | |
sed 's/cert1/cert2/; s/key1/key2/' -i postgres0.yml | |
kill -SIGHUP $PID | |
while ! check C=AU; do sleep 1; done | |
echo "$(curtime) Swapping to cert 1" | |
sed 's/cert2/cert1/; s/key2/key1/' -i postgres0.yml | |
kill -SIGHUP $PID | |
while ! check C=EE; do sleep 1; done | |
done | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
import time | |
import urllib3 | |
urllib3.disable_warnings() | |
try: | |
start_time = last_report = time.time() | |
fail = success = n = 0 | |
last_n = last_fail = last_success = 0 | |
while True: | |
try: | |
result = requests.get('https://localhost:8008/', timeout=2, verify=False) | |
was_success = result.status_code == 200 | |
except Exception as e: | |
sys.stdout.write(str(e) + "\n") | |
was_success = False | |
cur_time = time.time() | |
n += 1 | |
success += was_success | |
fail += not was_success | |
if cur_time - last_report > 1: | |
rate = (n - last_n) / (cur_time - last_report) | |
full_rate = n / (cur_time - start_time) | |
sys.stdout.write( | |
f"{'OK' if was_success else 'NOK'} {success} vs {fail} of {n} {full_rate} req/s {success - last_success} " | |
f"vs {fail - last_fail} failed of {n - last_n} {rate} req/s \n") | |
sys.stdout.flush() | |
last_fail, last_success, last_n = fail, success, n | |
last_report = cur_time | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment