graphql-engine/server/tests-py/utils.py
Brandon Simmons 9c9bb43a53 server: restore proper batching behavior in event trigger processing (#1237)
This essentially restores the original code from c425b554b8
(https://github.com/hasura/graphql-engine/pull/4013). Prior to this
commit we would slurp messages as fast as possible from the database
(one thing c425b55 fixed).

Another thing broken as a consequence of the same logic was the
removeEventFromLockedEvents logic which unlocks in-flight events
(breaking at-least-once delivery)

Some archeology, post-c425b55:

- cc8e2ccc erroneously attempted to refactor using `bracket`, resulting
  in the same slurp-all-events behavior (since we don't ever wait for
  processEvent to complete)
- at some point event processing within a batch is made serial, this
  reported as a bug. See: https://github.com/hasura/graphql-engine/issues/5189
- in 0ef52292b5 (which I approved...) an `async` is added, again
  causing the same issue...

GitOrigin-RevId: d8cbaab385267a4c3f1f173e268a385265980fb1
2021-04-29 04:02:05 +00:00

20 lines
555 B
Python

# Various testing utility functions
import time
# Loop a function 'tries' times, until all assertions pass. With a 0.3 second
# pause after each. This re-raises AssertionError in case we run out of tries
def until_asserts_pass(tries, func):
for x in range(0, tries):
print(x)
if x == tries-1:
# last time; raise any assertions in caller:
func()
else:
try:
func()
break
except AssertionError:
time.sleep(0.3)
pass