-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathtest_io_hooks.py
More file actions
153 lines (99 loc) · 4.41 KB
/
Copy pathtest_io_hooks.py
File metadata and controls
153 lines (99 loc) · 4.41 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from __future__ import print_function
import json
def test_io_hooks_nothing(worker):
worker.start(flags=" --config tests/fixtures/config-io-hooks.py")
assert worker.send_task(
"tests.tasks.general.Add", {"a": 41, "b": 1}) == 42
events = json.loads(
worker.send_task("tests.tasks.general.GetIoHookEvents", {}))
job_events = [x for x in events if x.get("job")]
for evt in job_events:
print(evt)
# Only update should be the result in mongodb.
assert len(job_events) == 1 * 2
assert job_events[0]["hook"] == "mongodb_pre"
assert job_events[1]["hook"] == "mongodb_post"
assert job_events[0]["method"] == "update"
assert job_events[1]["method"] == "update"
assert job_events[0]["collection"] == "mrq.mrq_jobs"
assert job_events[1]["collection"] == "mrq.mrq_jobs"
def test_io_hooks_redis(worker):
worker.start(flags=" --config tests/fixtures/config-io-hooks.py")
worker.send_task(
"tests.tasks.io.TestIo",
{"test": "redis-llen", "params": {"key": "xyz"}}
)
events = json.loads(
worker.send_task("tests.tasks.general.GetIoHookEvents", {}))
job_events = [x for x in events if x.get("job")]
for evt in job_events:
print(evt)
assert len(job_events) == 2 * 2
assert job_events[0]["hook"] == "redis_pre"
assert job_events[1]["hook"] == "redis_post"
assert job_events[0]["key"] == "xyz"
assert job_events[1]["key"] == "xyz"
assert job_events[0]["command"] == "LLEN"
assert job_events[1]["command"] == "LLEN"
# Regular MongoDB update
assert job_events[2]["hook"] == "mongodb_pre"
assert job_events[3]["hook"] == "mongodb_post"
assert job_events[2]["method"] == "update"
assert job_events[3]["method"] == "update"
assert job_events[2]["collection"] == "mrq.mrq_jobs"
assert job_events[3]["collection"] == "mrq.mrq_jobs"
def test_io_hooks_mongodb(worker):
worker.start(flags=" --config tests/fixtures/config-io-hooks.py")
ret = worker.send_task(
"tests.tasks.io.TestIo",
{"test": "mongodb-full-getmore"}
)
print(ret)
events = json.loads(
worker.send_task("tests.tasks.general.GetIoHookEvents", {}))
job_events = [x for x in events if x.get("job")]
for evt in job_events:
print(evt)
# First, insert
assert job_events[0]["hook"] == "mongodb_pre"
assert job_events[1]["hook"] == "mongodb_post"
assert job_events[0]["collection"] == "mrq.tests_inserts"
assert job_events[1]["collection"] == "mrq.tests_inserts"
assert job_events[0]["method"] == "insert_many"
assert job_events[1]["method"] == "insert_many"
# Then first query
assert job_events[2]["hook"] == "mongodb_pre"
assert job_events[3]["hook"] == "mongodb_post"
assert job_events[2]["collection"] == "mrq.tests_inserts"
assert job_events[3]["collection"] == "mrq.tests_inserts"
assert job_events[2]["method"] == "find"
assert job_events[3]["method"] == "find"
# Then getmore query
assert job_events[4]["hook"] == "mongodb_pre"
assert job_events[5]["hook"] == "mongodb_post"
assert job_events[4]["collection"] == "mrq.tests_inserts"
assert job_events[5]["collection"] == "mrq.tests_inserts"
assert job_events[4]["method"] == "cursor"
assert job_events[5]["method"] == "cursor"
# Then getmore query (can't understand why there are 2 more of those)
assert job_events[6]["hook"] == "mongodb_pre"
assert job_events[7]["hook"] == "mongodb_post"
assert job_events[6]["collection"] == "mrq.tests_inserts"
assert job_events[7]["collection"] == "mrq.tests_inserts"
assert job_events[6]["method"] == "cursor"
assert job_events[7]["method"] == "cursor"
# Then getmore query
assert job_events[8]["hook"] == "mongodb_pre"
assert job_events[9]["hook"] == "mongodb_post"
assert job_events[8]["collection"] == "mrq.tests_inserts"
assert job_events[9]["collection"] == "mrq.tests_inserts"
assert job_events[8]["method"] == "cursor"
assert job_events[9]["method"] == "cursor"
# Result MongoDB update
assert job_events[10]["hook"] == "mongodb_pre"
assert job_events[11]["hook"] == "mongodb_post"
assert job_events[10]["method"] == "update"
assert job_events[11]["method"] == "update"
assert job_events[10]["collection"] == "mrq.mrq_jobs"
assert job_events[11]["collection"] == "mrq.mrq_jobs"
assert len(job_events) == 6 * 2