Skip to content

Load test script

Ritik kumar edited this page Mar 7, 2021 · 1 revision

Script to make multiple signups concurrently.

  • Modify signup API to return UUID for email verification as well.
import concurrent.futures
import time

username_tuples = [
    # ['codechef', 'codeforces', 'hackerank', 'spoj']
    # ['ritikkne', 'ritik', 'ritikkne', 'dev_ritik'],
    # ['ritikkne', 'dev-ritik', 'ritikkne', 'dev_ritik'],
    # ['arihantjain456', 'arihant456', 'arihant456', 'aeromaster456'],
    # ['prateek1947', 'c0ding_dem0n', 'psachan2', ''],
    # ['codeit', 'tourist', '', ''],
    # ['rahuldugar', 'amnesiac_dusk', 'rahuldugarrd', 'rahuldugar'],
    # ['rahuldugar', 'amnesiac_dusk', 'rahuldugarrd', 'rahuldugar'],
    # ['vardhan_hs', 'hvsingh', '', ''],
    # ['aniket9465', 'aniket9465', 'aniket9465', 'aniket9465'],
    # ['aniket21', 'Quick.Silver', '', ''],
    # ['partitions', 'aniketsingh.sachan', 'aniketsingh_sac1', 'an1k3t03'],
    # ['codekaust', 'codekaust', 'codekaust', ''],
    # ['sauram228', 'enatsu__8', 'ss0274307', ''],
    # ['', 'triedodin', '', 'triedodin'],
    # ['jsuyash_1514', 'jsuyash1514', 'jsuyash1514', ''],
    # ['karthik0210', '', '', ''],
    # ['arnesh07', 'arnesh07', 'arnesh07', ''],
    # ['karan_1808', 'karan1808', '', ''],
    # ['manasvipatidar', 'manasvipatidar', '', ''],
    # ['overlord007', 'overlord007', '', ''],
    # ['gvaibhav21', 'gvaibhav22', 'gvaibhav21', 'gvaibhav21'],
    # ['gvaibhav21', 'gvaibhav22', 'gvaibhav21', 'gvaibhav21'],
    # ['harshhx17', 'harshhx17', 'harshhx17', 'harshhx17'],
    # ['spj_29', 'spj_29', 'spj_29', 'spj29'],
    # ['deva2802', 'deva2802', 'deva2802', 'deva2802'],
    # ['saharshluthra', 'saharshluthra', 'saharsh', 'saharshluthra'],
    # ['adkroxx', 'adkroxx', 'adkroxx', 'adkroxx'],
    # ['adarshkr532', 'ak532', 'adarshkr532', 'adarshkr532'],
    # ['pulkonet', 'pulkonet', 'pulkonet', ''],
    # ['codaira', 'codaira', 'codaira', ''],
]


def fun(count):
    print('running', count)
    import requests

    url = "http://localhost:8080/v1/user/signup"

    data = {
        'username': 'test-%d-%d' % (time.time_ns(), count),
        'email': 'email-%d-%[email protected]' % (time.time_ns(), count),
        'password': '12345678',
        'fullname': 'ritik',
        'institute': 'IITR',
        'handle.codechef': username_tuples[count][0],
        'handle.codeforces': username_tuples[count][1],
        'handle.hackerrank': username_tuples[count][2],
        'handle.spoj': username_tuples[count][3]
    }

    headers = {
        'accept': 'application/json',
        'content-type': 'application/x-www-form-urlencoded'
    }

    response = requests.request("POST", url, headers=headers, data=data)

    print(response.status_code)
    if response.status_code == 201:
        print(response.json())
        url = "http://localhost:8080/v1/user/confirm/%s" % response.json()["uuid"]
        print(url)
        response = requests.request("GET", url)

        print(response.text)
    else:
        print(response.text.encode('utf8'))
    print()


with concurrent.futures.ProcessPoolExecutor(max_workers=30) as e:
    futures = [e.submit(fun, count) for count in range(len(username_tuples))]
    i = 0

    for f in futures:
        if f.result() and len(f.result()) > 0:
            print(f.result())
Clone this wiki locally