Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-processing for realistic scenarios #5825

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .azure-pipelines-templates/trace_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ steps:
set -ex
cd tla/
parallel 'JSON={} ./tlc.sh consensus/Traceccfraft.tla' ::: \
../build/replicate.ndjson \
../build/election.ndjson \
../build/multi_election.ndjson \
../build/check_quorum.ndjson \
../build/reconnect.ndjson \
../build/reconnect_node.ndjson \
../build/bad_network.ndjson \
../build/fancy_election.1.ndjson \
../build/fancy_election.2.ndjson \
../build/suffix_collision.1.ndjson \
../build/suffix_collision.2.ndjson \
../build/suffix_collision.3.ndjson
../build/replicate_deprecated.ndjson \
../build/election_deprecated.ndjson \
../build/multi_election_deprecated.ndjson \
../build/check_quorum_deprecated.ndjson \
../build/reconnect_deprecated.ndjson \
../build/reconnect_node_deprecated.ndjson \
../build/bad_network_deprecated.ndjson \
../build/fancy_election.1_deprecated.ndjson \
../build/fancy_election.2_deprecated.ndjson \
../build/suffix_collision.1_deprecated.ndjson \
../build/suffix_collision.2_deprecated.ndjson \
../build/suffix_collision.3_deprecated.ndjson
displayName: "Run trace validation"
File renamed without changes.
File renamed without changes.
37 changes: 34 additions & 3 deletions tests/raft_scenarios_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import argparse
import sys
import os
import json
from subprocess import Popen, PIPE
from raft_scenarios_gen import generate_scenarios
from contextlib import contextmanager
from collections import defaultdict
from heapq import merge


@contextmanager
Expand Down Expand Up @@ -33,15 +36,40 @@ def write_error_report(errors=None):
print("??? success \n")


def separate_log_lines(text):
def remove_reconfiguration_replicates(log):
log_by_node = defaultdict(list)
for line in log:
entry = json.loads(line)
node = entry["msg"]["state"]["node_id"]
if entry["msg"]["function"] == "add_configuration":
removed = log_by_node[node].pop()
assert removed["msg"]["function"] in (
"replicate",
"execute_append_entries_sync",
), removed
log_by_node[node].append(entry)
return [
json.dumps(e)
for e in merge(*log_by_node.values(), key=lambda e: int(e["h_ts"]))
]


def noop(log):
return log


def separate_log_lines(text, preprocess):
mermaid = []
log = []
for line in text.split(os.linesep):
if line.startswith("<RaftDriver>"):
mermaid.append(line[len("<RaftDriver>") :])
elif '"raft_trace"' in line:
log.append(line)
return (os.linesep.join(mermaid) + os.linesep, os.linesep.join(log) + os.linesep)
return (
os.linesep.join(mermaid) + os.linesep,
os.linesep.join(preprocess(log)) + os.linesep,
)


def expand_files(files):
Expand Down Expand Up @@ -94,7 +122,10 @@ def expand_files(files):
with block(ostream, "stderr", 3):
ostream.write(err.decode())

mermaid, log = separate_log_lines(out.decode())
mermaid, log = separate_log_lines(
out.decode(),
noop if "deprecated" in scenario else remove_reconfiguration_replicates,
)

with block(ostream, "diagram", 3, "mermaid", ["sequenceDiagram"]):
ostream.write(mermaid)
Expand Down