-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cron.py
78 lines (48 loc) · 2.07 KB
/
test_cron.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python3
import os
from genezio import genezio_deploy, genezio_login, genezio_local, genezio_delete
from utils import run_node_script, kill_process
import time
def test_hello():
print("Starting cron test...")
token = os.environ.get('GENEZIO_TOKEN')
genezio_login(token)
os.chdir("./projects/crons/")
deploy_result = genezio_deploy(False)
assert deploy_result.return_code == 0, "genezio deploy returned non-zero exit code"
assert deploy_result.project_url != "", "genezio deploy returned empty project url"
os.chdir("./client/")
status, output = run_node_script("test-cron.js")
assert status == 0, "Node test script returned non-zero exit code"
number = int(output)
print("Testing on remote server...")
print("First request. Number is " + str(number))
time.sleep(61)
status, output = run_node_script("test-cron.js")
assert status == 0, "Node test script returned non-zero exit code"
numberAfterOneMinute = int(output)
print("Second request. Number is " + str(numberAfterOneMinute))
assert numberAfterOneMinute > number, "Cron job did not run"
os.chdir("../")
process = genezio_local()
assert process != None, "genezio local returned None"
os.chdir("./client/")
status, output = run_node_script("test-cron.js")
assert status == 0, "Node test script returned non-zero exit code"
number = int(output)
print("Testing on local server...")
print("First request. Number is " + str(number))
time.sleep(61)
status, output = run_node_script("test-cron.js")
assert status == 0, "Node test script returned non-zero exit code"
numberAfterOneMinute = int(output)
print("Second request. Number is " + str(numberAfterOneMinute))
assert numberAfterOneMinute > number, "Cron job did not run"
kill_process(process)
os.chdir("../")
print("Prepared to delete project...")
genezio_delete(deploy_result.project_id)
print("Test passed!")
# Test order matters because the commands are having side effects.
if __name__ == '__main__':
test_hello()