-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration: fix crash due to failed heartbeats not propagating
Fixes PL-131744
- Loading branch information
Showing
10 changed files
with
427 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# | ||
# Show reporting of all expectations and which of those lines were found | ||
# | ||
# | ||
import re | ||
import typing | ||
|
||
WARN_SYMBOL = "🟡" | ||
OK_SYMBOL = "⚪️" | ||
|
||
|
||
def match(pattern, line): | ||
pattern = pattern.replace("\t", " " * 8) | ||
line = line.replace("\t", " " * 8) | ||
pattern = re.escape(pattern) | ||
pattern = pattern.replace(r"\.\.\.", ".+?") | ||
pattern = re.compile("^" + pattern + "$") | ||
return pattern.match(line) | ||
|
||
|
||
class Line: | ||
matched = False | ||
|
||
def __init__(self, data: str): | ||
self.data = data | ||
|
||
def matches(self, expectation: str): | ||
matched = bool(match(expectation, self.data)) | ||
self.matched |= matched | ||
return matched | ||
|
||
|
||
class Audit: | ||
lines: typing.List[Line] | ||
unmatched_expectations: typing.List[str] | ||
|
||
def __init__(self, content): | ||
self.lines = [] | ||
self.unmatched_expectations = [] | ||
|
||
for line in content.splitlines(): | ||
self.lines.append(Line(line)) | ||
|
||
def expect(self, lines: str): | ||
"""Expect all lines exist and come in order, but they | ||
may be interleaved with other lines.""" | ||
lines = lines.strip() | ||
scan = iter(self.lines) | ||
for expected in lines.splitlines(): | ||
if not expected: | ||
continue | ||
for line in scan: | ||
if line.matches(expected): | ||
break | ||
else: | ||
self.unmatched_expectations.append(expected) | ||
# Reset the scan, maybe the other lines will match | ||
scan = iter(self.lines) | ||
|
||
def maybe(self, lines: str): | ||
"""Those lines may exist and then they may appear anywhere | ||
a number of times, or they may not exist. | ||
""" | ||
lines = lines.strip() | ||
for expected in lines.splitlines(): | ||
scan = iter(self.lines) | ||
for line in scan: | ||
line.matches(expected) | ||
|
||
def report(self): | ||
yield "String did not meet the expectations." | ||
yield "" | ||
yield OK_SYMBOL + "=OK " | ||
yield WARN_SYMBOL + "=UNEXPECTED" | ||
yield "" | ||
yield "Here is string that was tested: " | ||
yield "" | ||
for line in self.lines: | ||
if line.matched: | ||
prefix = OK_SYMBOL | ||
else: | ||
prefix = WARN_SYMBOL | ||
yield prefix + " " + line.data | ||
if self.unmatched_expectations: | ||
yield "" | ||
yield "Unmatched expectations: " | ||
yield "" | ||
for line in self.unmatched_expectations: | ||
yield WARN_SYMBOL + " " + line | ||
|
||
def is_ok(self): | ||
if self.unmatched_expectations: | ||
return False | ||
for line in self.lines: | ||
if not line.matched: | ||
return False | ||
return True | ||
|
||
|
||
class Pattern: | ||
def __init__(self): | ||
self.ops = [] | ||
|
||
def expect(self, lines: str): | ||
self.ops.append(("expect", lines)) | ||
|
||
def maybe(self, lines: str): | ||
self.ops.append(("maybe", lines)) | ||
|
||
def _audit(self, other): | ||
audit = Audit(other) | ||
for op, *args in self.ops: | ||
getattr(audit, op)(*args) | ||
return audit | ||
|
||
def __eq__(self, other): | ||
assert isinstance(other, str) | ||
report = self._audit(other) | ||
return report.is_ok() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.