differential

package
v1.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package differential runs Cypher corpora against NornicDB and the pinned Neo4j and ratchets the statements whose answers differ (#754).

Two corpora are compared, through every route a client uses (Bolt auto-commit, a Bolt explicit transaction, HTTP /tx/commit):

  • the sweep (testdata/differential/sweep.json.gz, generated by scripts/cypher-tck/differential/gen_sweep.py with make cypher-sweep, not checked in): statements for every operator and clause family on one small graph (#907);
  • the issue reproductions (testdata/differential/issues.json, extracted by scripts/cypher-tck/differential/extract_issue_corpus.py): the Cypher in the issue texts, run in each issue's order on an empty graph.

The known differences are listed in testdata/differential/known_mismatches.jsonl, one per statement and route, each with the issue that tracks it. A run fails when a statement that matched starts to differ, and reports the listed statements that now match so the list can be trimmed in the same change.

Index

Constants

View Source
const ReportEnv = "NORNICDB_DIFFERENTIAL_REPORT"

ReportEnv names a file a check appends every differing statement to, one JSON object per line with its route and both outcomes, for reading a run's differences in full; the test output lists only the first maxReported.

View Source
const SweepIssue = 907

SweepIssue is the issue that tracks the sweep's differences.

View Source
const UpdateRatchetEnv = "NORNICDB_DIFFERENTIAL_UPDATE_RATCHET"

UpdateRatchetEnv, set to 1, rewrites a route's entries in the ratchet file from UpdateRuns runs instead of checking one run against them.

View Source
const UpdateRuns = 3

UpdateRuns is how many times an update runs a route: a statement that matches Neo4j in some runs and not in others is listed as unstable.

Variables

View Source
var DefaultOptions = Options{StatementTimeout: 20 * time.Second, Workers: 4, ResetAttempts: 3, OrderRetries: 2}

DefaultOptions keep a full run within a CI job's budget: no statement can hold the run longer than its timeout.

View Source
var GraphStateQueries = []string{
	"MATCH (n) RETURN labels(n) AS labels, properties(n) AS properties",
	"MATCH (a)-[r]->(b) RETURN properties(a) AS start, type(r) AS type, properties(r) AS properties, properties(b) AS end",
}

GraphStateQueries read a graph's nodes and relationships in a form both servers and every route answer alike; the outcomes compare as multisets.

Functions

func Arbitrary

func Arbitrary(query string) bool

Arbitrary reports whether query keeps arbitrary rows: a LIMIT or SKIP with no ORDER BY since its clause's WITH or RETURN. Which rows such a clause keeps isn't defined (in Neo4j either), so neither are its rows nor what it writes.

func Assert

func Assert(t testing.TB, path, route string, run func() ([]Result, int, error))

Assert runs a route (run returns its results and the resets it retried) and checks the results against the ratchet file at path, or, when UpdateRatchetEnv is 1, runs it UpdateRuns times and rewrites the route's entries. A check fails t for every statement that differs from Neo4j and isn't listed, and lists the entries that match now so they can be removed.

func OrderOnly

func OrderOnly(query string, reference, actual Outcome) bool

OrderOnly reports whether two outcomes of query that don't agree (Same) differ only in the order of their rows: the same rows, as a multiset.

func Same

func Same(query string, reference, actual Outcome) bool

Same reports whether two outcomes of query agree, as the sweep compares them (#907):

  • two errors agree when their status codes are equal, whatever the text;
  • an error and rows never agree;
  • rows agree when the columns are equal and the rows are equal, in order when query has ORDER BY and as a multiset otherwise;
  • rows that tie under the RETURN's ORDER BY have no defined order among themselves (in Neo4j either): when every sort key is a returned column, each run of rows with equal keys compares as a multiset;
  • a collect() with no ORDER BY before it has no defined element order (in Neo4j either), so list values of such a statement compare as multisets;
  • labels() and keys() list token names in an order that depends on the database's history (in Neo4j, the order the names were first used), so a returned column that is one of them compares as a set of names;
  • a statement that keeps arbitrary rows (Arbitrary) compares its columns and its number of rows only.

func SameGraphState

func SameGraphState(reference, actual Outcome) bool

SameGraphState reports whether two answers of a GraphStateQueries statement agree: rows as a multiset, label lists in any order.

func Writes

func Writes(query string) bool

Writes reports whether query may change the graph in a defined way, so the graph state after it is compared too: it writes, and doesn't write to arbitrary rows (Arbitrary).

Types

type Entry

type Entry struct {
	ID       string `json:"id"`
	Route    string `json:"route"`
	Issue    int    `json:"issue"`
	Unstable bool   `json:"unstable,omitempty"`
	Intended bool   `json:"intended,omitempty"`
}

Entry is one known difference: a statement (or a statement's graph state) that differs from Neo4j through one route, and the issue that tracks it. An Unstable entry sometimes matches and sometimes doesn't (rows tied under an ORDER BY, say); checks skip it. An Intended entry is a difference kept on purpose (an extension, or a decision not to follow Neo4j); its Issue is where that was decided, not a defect to fix.

A run's Issue is its corpus's (SweepIssue for the sweep). An entry filed under another issue by hand, or marked Intended, keeps both through Update while the statement still differs.

type Executor

type Executor interface {
	// Execute runs query and returns its outcome; a failure is an Outcome
	// with a Code, never an error of the harness.
	Execute(ctx context.Context, query string) Outcome
	// Reset empties the graph, indexes and constraints included.
	Reset(ctx context.Context) error
}

Executor runs statements through one route on one server. Implementations are safe for concurrent use.

type IssueCase

type IssueCase struct {
	Issue      int              `json:"issue"`
	Title      string           `json:"title"`
	Statements []IssueStatement `json:"statements"`
}

IssueCase is the Cypher of one issue's text, in the issue's order.

func LoadIssues

func LoadIssues(path string) ([]IssueCase, error)

LoadIssues reads the issue-reproduction corpus at path.

type IssueStatement

type IssueStatement struct {
	ID    string `json:"id"`
	Query string `json:"query"`
}

IssueStatement is one statement of an issue.

type Options

type Options struct {
	StatementTimeout time.Duration
	Workers          int
	ResetAttempts    int
	OrderRetries     int
}

Options bound a run: each statement's deadline, the number of statements read in parallel, how often a reset is retried after a transient error, and how often a read whose rows came back in another order runs again (rerunOrder).

type Outcome

type Outcome struct {
	Columns []string `json:"columns,omitempty"`
	Rows    [][]any  `json:"rows,omitempty"`
	// Code is the error's Neo4j status code; "" when the statement succeeded.
	// A client-side failure (a timeout, a broken connection) is
	// "client:<description>".
	Code string `json:"code,omitempty"`
	// Message is the error's text, kept for reports only: the status code is
	// the contract, the wording is each server's own.
	Message string `json:"message,omitempty"`
}

Outcome is one statement's answer through one route: its columns and rows, or the status code of its error. Values are in a route's normalized form (NormalizeBoltValue for Bolt, the response JSON for HTTP), the same form on both servers.

func (Outcome) Failed

func (outcome Outcome) Failed() bool

Failed reports whether the statement failed.

type Pair

type Pair struct {
	Neo4j    Executor
	NornicDB Executor
	// ResetRetries counts the resets retried after a transient error (#732's
	// race), reported with the run.
	ResetRetries int
	// contains filtered or unexported fields
}

Pair is a route's two servers.

type Ratchet

type Ratchet map[string]map[string]Entry

Ratchet is the known differences, by route and id.

func LoadRatchet

func LoadRatchet(path string) (Ratchet, error)

LoadRatchet reads the ratchet file: one JSON Entry per line. A missing file is an empty ratchet.

func (Ratchet) Check

func (ratchet Ratchet) Check(route string, results []Result) Report

Check compares results, every statement of route, with its listed differences.

func (Ratchet) Update

func (ratchet Ratchet) Update(path, route string, runs [][]Result) error

Update replaces route's entries with the differences of runs (repeated runs of every statement of the route) and writes the file, sorted, keeping the other routes' entries. A statement that differs in every run is listed; one that differs in some runs only is listed as unstable.

type Report

type Report struct {
	Route      string
	Compared   int
	Known      int
	Unstable   int
	Regressed  []Result // differ from Neo4j and aren't listed
	NowMatches []Entry  // listed, and match Neo4j now
	Stale      []Entry  // listed, and no longer compared
}

Report is a run checked against the ratchet.

type Result

type Result struct {
	ID       string  `json:"id"`
	Issue    int     `json:"issue"`
	Kind     string  `json:"kind"`
	Query    string  `json:"query"`
	Neo4j    Outcome `json:"neo4j"`
	NornicDB Outcome `json:"nornicdb"`
	Match    bool    `json:"match"`
}

Result is one statement's outcome on both servers. A graph-state result (Kind "graph") compares the graph after a statement that writes; its ID is the statement's with a ":graph" suffix.

func RunCorpora

func RunCorpora(ctx context.Context, pair *Pair, sweep SweepCorpus, issues []IssueCase, logf func(string, ...any)) ([]Result, int, error)

RunCorpora runs the sweep and the issue reproductions on pair, as one differential.Assert run: their results, and the resets retried so far.

func RunIssues

func RunIssues(ctx context.Context, issues []IssueCase, pair *Pair, options Options) ([]Result, error)

RunIssues compares every issue's statements on pair, issue by issue, each on an empty graph and in the issue's order. After a statement that writes, the graph state is compared too.

func RunSweep

func RunSweep(ctx context.Context, corpus SweepCorpus, pair *Pair, options Options) ([]Result, error)

RunSweep compares every sweep case on pair. The read-only cases run first, options.Workers at a time, on Setup's graph; each case that writes then runs alone, with its graph state compared, and the graph is set up again after it.

type StatementSequenceExecutor

type StatementSequenceExecutor interface {
	ExecuteStatements(context.Context, string, []string) Outcome
}

StatementSequenceExecutor runs one database-scoped request, retaining the transaction across statements and returning the last statement or first error.

type SweepCase

type SweepCase struct {
	ID       string `json:"id"`
	Family   string `json:"family"`
	Position string `json:"position"`
	Query    string `json:"query"`
	Rollback bool   `json:"rollback"`

	// Optional database and statement sequence retain one request/transaction.
	Database   string   `json:"database,omitempty"`
	Statements []string `json:"statements,omitempty"`
}

SweepCase is one generated statement. A Rollback case writes: the graph is restored after it.

type SweepCorpus

type SweepCorpus struct {
	Setup []string    `json:"setup"`
	Cases []SweepCase `json:"cases"`
}

SweepCorpus is the generated sweep: Setup creates the graph every case reads.

func LoadSweep

func LoadSweep(path string) (SweepCorpus, error)

LoadSweep reads the gzipped sweep corpus at path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL