Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest # nosemgrep : semgrep.dev/s/swati31196:github_provided_runner
strategy:
max-parallel: 4
matrix:
python-version: [3, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.12.0"
- name: Install dependencies
run: |
pip install setuptools
Expand All @@ -31,3 +28,10 @@ jobs:
python3 setup.py install
- name: Run Tests
run: python3 -m unittest
- name: Print Python Version
run: python3 --version
- name: Run order Test
env:
RZP_API_KEY: ${{ secrets.RZP_API_KEY }}
RZP_API_SECRET: ${{ secrets.RZP_API_SECRET }}
run: bash run_parallel_orders.sh
41 changes: 41 additions & 0 deletions order_connect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import razorpay
import logging
import http.client as http_client
import time
import random
import os


# Enable HTTP debugging
# http_client.HTTPConnection.debuglevel = 1
# logging.basicConfig()
# logging.getLogger().setLevel(logging.DEBUG)
# requests_log = logging.getLogger("requests.packages.urllib3")
# requests_log.setLevel(logging.DEBUG)
# requests_log.propagate = True

api_key = os.getenv('RZP_API_KEY')
api_secret = os.getenv('RZP_API_SECRET')

if not api_key or not api_secret:
raise ValueError("Please set RZP_API_KEY and RZP_API_SECRET environment variables")

client = razorpay.Client(auth=(api_key, api_secret))


for i in range(15):
try:
x = client.payment.fetch("pay_R2IbWHkb3nGCa9")

print(f"Request {i+1}/15 at {time.strftime('%Y-%m-%d %H:%M:%S')}: {x}")

except Exception as e:
print(f"Error in request {i+1}/15: {e}")

# Random delay between 1-5 seconds (skip delay after last request)
if i < 14:
delay = random.uniform(1, 5)
print(f"Waiting {delay:.1f} seconds...")
time.sleep(delay)

print("Completed all 15 requests!")
20 changes: 16 additions & 4 deletions razorpay/client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import json
import requests
import pkg_resources
import importlib.metadata

from pkg_resources import DistributionNotFound
from importlib.metadata import PackageNotFoundError

from types import ModuleType

Expand Down Expand Up @@ -84,8 +84,20 @@ def _update_user_agent_header(self, options):
def _get_version(self):
version = ""
try: # nosemgrep : gitlab.bandit.B110
version = pkg_resources.require("razorpay")[0].version
except DistributionNotFound: # pragma: no cover
# Try importlib.metadata first (modern approach)
try:
import importlib.metadata
from importlib.metadata import PackageNotFoundError
version = importlib.metadata.version("razorpay")
except ImportError:
# Fall back to pkg_resources
import pkg_resources
from pkg_resources import DistributionNotFound
version = pkg_resources.require("razorpay")[0].version
except (PackageNotFoundError, DistributionNotFound, NameError): # pragma: no cover
# PackageNotFoundError: importlib.metadata couldn't find the package
# DistributionNotFound: pkg_resources couldn't find the package
# NameError: in case the exception classes aren't defined due to import issues
pass
return version

Expand Down
88 changes: 88 additions & 0 deletions run_parallel_orders.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

# Create logs directory if it doesn't exist
mkdir -p logs

# Clear any existing log files
rm -f logs/order_*.log

echo "Starting 10 parallel instances of order_connect.py..."
echo "Logs will be saved in the 'logs' folder"
echo "================================================"

# Record start time
start_time=$(date +%s)
start_time_readable=$(date)

# Array to store process IDs
pids=()

# Start 10 parallel processes
for i in {1..10}; do
echo "Starting instance $i..."
python3 order_connect.py > logs/order_instance_$i.log 2>&1 &
pids+=($!)
done

echo "All 10 instances started. PIDs: ${pids[@]}"
echo "Waiting for all processes to complete..."

# Wait for all background processes to complete
for pid in "${pids[@]}"; do
wait $pid
echo "Process $pid completed"
done

# Record end time
end_time=$(date +%s)
end_time_readable=$(date)

# Calculate execution time and RPS
execution_time=$((end_time - start_time))
total_requests=150 # 10 instances * 15 requests each
rps=$(echo "scale=2; $total_requests / $execution_time" | bc -l)

echo "================================================"
echo "All instances completed!"
echo "Execution Summary:"
echo "- Start time: $start_time_readable"
echo "- End time: $end_time_readable"
echo "- Total execution time: ${execution_time} seconds"
echo "- Total requests: $total_requests"
echo "- Requests per second (RPS): $rps"
echo "================================================"
echo "Check the logs folder for individual instance outputs:"
ls -la logs/

# Optional: Create a summary log
echo "Creating summary log..."
echo "Summary of all parallel order creation attempts" > logs/summary.log
echo "Generated at: $(date)" >> logs/summary.log
echo "================================================" >> logs/summary.log
echo "EXECUTION STATISTICS:" >> logs/summary.log
echo "- Start time: $start_time_readable" >> logs/summary.log
echo "- End time: $end_time_readable" >> logs/summary.log
echo "- Total execution time: ${execution_time} seconds" >> logs/summary.log
echo "- Total requests: $total_requests (10 instances × 15 requests each)" >> logs/summary.log
echo "- Requests per second (RPS): $rps" >> logs/summary.log
echo "================================================" >> logs/summary.log

for i in {1..10}; do
echo "" >> logs/summary.log
echo "=== Instance $i ===" >> logs/summary.log
if [ -f "logs/order_instance_$i.log" ]; then
cat logs/order_instance_$i.log >> logs/summary.log
else
echo "Log file not found for instance $i" >> logs/summary.log
fi
done

echo "Summary log created at logs/summary.log"
echo "Individual logs available at logs/order_instance_[1-10].log"

# Display summary log content in terminal
echo ""
echo "================================================"
echo "SUMMARY LOG CONTENT:"
echo "================================================"
cat logs/summary.log
Loading