-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
58 lines (46 loc) · 1.68 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import multiprocessing
from multiprocessing import Pool, Value
import os
import time
import requests
from main.helpers.publish_pubsub import make_payment
from main.helpers.insert_to_basket_cloud_func import add_basket
success = 0
fail = 0
def worker1():
returned = make_payment()
if returned == "OK":
print("{}-> ok".format(os.getpid()))
else:
print("{}-> not ok".format(os.getpid()))
def worker2():
returned = add_basket("Headphone")
if returned.status_code == 200:
print("{}-> ok".format(os.getpid()))
else:
print("{}-> not ok".format(os.getpid()))
if __name__ == "__main__":
processes1 = []
for i in range(100):
processes1.append(multiprocessing.Process(target=worker1))
pubsub_start = time.time()
print("---------------Starting PubSub Test--------------")
for i in range(100):
processes1[i].start()
for i in range(100):
processes1[i].join()
print("---------------PubSub Test Ended--------------")
pubsub_end = time.time()
processes2 = []
for i in range(100):
processes2.append(multiprocessing.Process(target=worker2))
addbasket_start = time.time()
print("---------------Starting Adding to Baskrt Test--------------")
for i in range(100):
processes2[i].start()
for i in range(100):
processes2[i].join()
print("---------------Adding to Basket Test Ended--------------")
addbasket_end = time.time()
print("PubSub Completion time -> {}".format(pubsub_end-pubsub_start))
print("Adding to Basket Test Completion Time -> {}".format(addbasket_end-addbasket_start))