Skip to content
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
4 changes: 4 additions & 0 deletions conformance/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (w *world) send(r request) result {
}
return w.sendRaw(r)
}
if r.plain {
// net/http's clients speak TLS to a file with tls, so plain HTTP to its port is sent by hand.
panic(fmt.Sprintf("the battery sends plain HTTP to a listener with tls as a raw request only, not %+v", r))
}
return w.sendOn(w.client(r), r)
}

Expand Down
167 changes: 163 additions & 4 deletions conformance/counts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,25 @@ func rowsOnFiles(files []fileKeys) map[string]int {

// pageCountProblems returns a line for each count of rows docs/conformance.md gives that differs from what the
// entries run, with the page's number and the counted one: the rows of each group of entries on each of its files,
// those of each group, and those in all. The counts used to be kept by hand, and went stale each time a row was added.
// those of each group, and those in all, the rows of each scenario on each file of Envoy's entry
// (scenarioCountProblems), and the rows sent as their scenario starts (overlapCountProblems). The counts used to be
// kept by hand, and went stale each time a row was added.
// It also returns a line when the page names a file a group runs no row on, when two entries of one group run
// different rows, and when an entry belongs to no group or to two, as the page gives one count for each group.
func pageCountProblems(ts []target, byEntry map[string][]fileKeys) []string {
text, err := os.ReadFile(countsPage)
if err != nil {
return []string{fmt.Sprintf("reading the counts of rows: %v", err)}
}
var envoy []fileKeys
if i := slices.IndexFunc(ts, func(tg target) bool { return tg.name == "envoy" }); i >= 0 {
envoy = byEntry[ts[i].label]
}
scenarioLines := slices.Concat(scenarioCountProblems(string(text), envoy), overlapCountProblems(string(text)))
passage := countsPassage.FindStringSubmatch(strings.Join(strings.Fields(string(text)), " "))
if passage == nil {
return []string{fmt.Sprintf("%s holds no passage from %q to %q, which gives the rows each entry runs", pageName,
"The scenarios run in this order: ", "in all")}
return append([]string{fmt.Sprintf("%s holds no passage from %q to %q, which gives the rows each entry runs", pageName,
"The scenarios run in this order: ", "in all")}, scenarioLines...)
}
breakdown, totals := passage[1], passage[2]
var lines []string
Expand Down Expand Up @@ -147,7 +154,159 @@ func pageCountProblems(ts []target, byEntry map[string][]fileKeys) []string {
}
lines = appendDiffering(lines, m[1], total, "the rows in "+g.words)
}
return appendDiffering(lines, passage[3], all, "the rows in all")
return append(appendDiffering(lines, passage[3], all, "the rows in all"), scenarioLines...)
}

// The table of the scenarios starts with its header and runs to the first line that is no row of it. Each row names a
// scenario in its first cell and ends its last with the rows the scenario runs on each file of Envoy's entry, the one
// entry that runs every file: "In Envoy's entry: " and a count on each file, such as "150 rows on `full`, `portable`
// and `nginx-file`" or "3 on `nginx-limits`", which may say after a count why a file runs fewer rows but holds no other
// number, so a count the battery cannot read in this form fails the run rather than go unchecked.
var (
scenarioTableHead = "| Scenario | Keys | What its rows check |\n|---|---|---|\n"
scenarioCounts = regexp.MustCompile("In Envoy's entry: (.*)\\.$")
countOnFiles = regexp.MustCompile("([0-9][0-9,]*) (?:rows? )?on (`[^`]+`(?:(?:, | and )`[^`]+`)*)")
)

// scenarioCountProblems returns a line for each count of rows the table of the scenarios in text gives that differs
// from what the scenario runs on that file of Envoy's entry, whose rendered files are envoy, with the page's number and
// the counted one. It also returns a line for a scenario with no row in the table or with two, a row that names no
// scenario or holds other than three cells, a last cell that does not end with the rows in Envoy's entry or holds a number it does
// not read as a count, a file a count names twice or that the scenario runs no row on, and a file the scenario runs
// rows on that no count names.
func scenarioCountProblems(text string, envoy []fileKeys) []string {
start := strings.Index(text, scenarioTableHead)
if start < 0 {
return []string{fmt.Sprintf("%s holds no table of the scenarios, a header %q", pageName, strings.SplitN(scenarioTableHead, "\n", 2)[0])}
}
byName := map[string][]string{}
var lines []string
for _, row := range strings.Split(text[start+len(scenarioTableHead):], "\n") {
if !strings.HasPrefix(row, "|") {
break
}
cell := cells(row)
switch {
case len(cell) != 3:
lines = append(lines, fmt.Sprintf("the row %q of the table of the scenarios in %s holds %d cells, where it must hold three: a | inside a cell is written \\|",
cell[0], pageName, len(cell)))
case byName[cell[0]] != nil:
// A second row of a name would be read in place of the first, so a stale count in either goes unread.
lines = append(lines, fmt.Sprintf("the table of the scenarios in %s has two rows of the scenario %q", pageName, cell[0]))
default:
byName[cell[0]] = cell
}
}
for _, s := range scenarios {
cell, ok := byName[s.name]
if !ok {
lines = append(lines, fmt.Sprintf("the table of the scenarios in %s has no row of the scenario %q", pageName, s.name))
continue
}
delete(byName, s.name)
counted := map[string]int{}
for _, f := range envoy {
for _, e := range s.exchanges {
if f.runs(s, e) {
counted[f.label]++
}
}
}
what := fmt.Sprintf("the rows of the scenario %q", s.name)
clause := scenarioCounts.FindStringSubmatch(cell[2])
if clause == nil || strings.Count(cell[2], "In Envoy's entry: ") != 1 {
lines = append(lines, fmt.Sprintf("%s's row of the scenario %q does not end with one sentence of its rows on each file of Envoy's entry, which starts %q",
pageName, s.name, "In Envoy's entry: "))
continue
}
pairs := countOnFiles.FindAllStringSubmatch(clause[1], -1)
if found := len(countNumber.FindAllString(backquoted.ReplaceAllString(clause[1], ""), -1)); found != len(pairs) {
lines = append(lines, fmt.Sprintf("%s holds %d numbers in %s on each file of Envoy's entry, %q, and the battery reads %d of them as counts",
pageName, found, what, clause[1], len(pairs)))
}
given := map[string]bool{}
for _, pair := range pairs {
for _, label := range backquoted.FindAllString(pair[2], -1) {
label = strings.Trim(label, "`")
switch _, runs := counted[label]; {
case given[label]:
lines = append(lines, fmt.Sprintf("%s names `%s` twice in %s in Envoy's entry", pageName, label, what))
case !runs:
lines = append(lines, fmt.Sprintf("%s gives %s as %s on `%s` in Envoy's entry, a file it runs no row on", pageName, pair[1], what, label))
default:
lines = appendDiffering(lines, pair[1], counted[label], fmt.Sprintf("%s on `%s` in Envoy's entry", what, label))
}
given[label] = true
}
}
for _, label := range slices.Sorted(maps.Keys(counted)) {
if !given[label] {
lines = append(lines, fmt.Sprintf("%s gives no count of %s on `%s` in Envoy's entry, and the battery counts %s",
pageName, what, label, commas(counted[label])))
}
}
}
for _, name := range slices.Sorted(maps.Keys(byName)) {
lines = append(lines, fmt.Sprintf("the table of the scenarios in %s has a row %q, which names no scenario", pageName, name))
}
return lines
}

// The rows sent as their scenario starts (exchange.overlap) are given in one sentence of the page, read with its white
// space made single spaces: those of every scenario but tracing, which wait for a proxy's timer or its close, and
// those of the tracing scenario, each a count in digits before these words.
const (
overlapOthers = "rows that wait for a proxy's timer or its close"
overlapTracing = "rows of the tracing scenario"
)

// overlapCountProblems returns a line when text, the page, does not give each count of the rows sent as their scenario
// starts once, or gives another number than the scenarios hold: the rows of the tracing scenario and those of the
// others. They are rows of the scenarios, whatever file runs them.
func overlapCountProblems(text string) []string {
flat := strings.Join(strings.Fields(text), " ")
var others, traced int
for _, s := range scenarios {
for _, e := range s.exchanges {
switch {
case !e.overlap:
case s.name == tracing.name:
traced++
default:
others++
}
}
}
var lines []string
for _, c := range []struct {
words string
counted int
}{{overlapOthers, others}, {overlapTracing, traced}} {
found := regexp.MustCompile("([0-9][0-9,]*) "+regexp.QuoteMeta(c.words)).FindAllStringSubmatch(flat, -1)
if len(found) != 1 {
lines = append(lines, fmt.Sprintf("%s gives %d times a count in digits of the %s, where it must give it once, and the battery counts %s",
pageName, len(found), c.words, commas(c.counted)))
continue
}
lines = appendDiffering(lines, found[0][1], c.counted, "the "+c.words)
}
return lines
}

// cells returns the cells of a row of a Markdown table, split at each | no backslash escapes, as GitHub splits it: a |
// inside a code span that is not escaped ends the cell there, and GitHub drops what comes after the third cell.
func cells(row string) []string {
var found []string
var cell strings.Builder
for i := 1; i < len(strings.TrimSuffix(row, "|")); i++ {
if row[i] == '|' && row[i-1] != '\\' {
found = append(found, strings.TrimSpace(cell.String()))
cell.Reset()
continue
}
cell.WriteByte(row[i])
}
return append(found, strings.TrimSpace(cell.String()))
}

// appendDiffering appends a line to lines when page, a count as the page writes it, is not counted, the count of what,
Expand Down
15 changes: 12 additions & 3 deletions conformance/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
// HEADERS frame of the same fields, each a literal HPACK field with no index and no Huffman coding, then the body as a
// DATA frame and the trailers as a second HEADERS frame, and reads frames until the stream ends. A closed or reset connection, or a
// GOAWAY, before the answer is an error, as a client sees a proxy that refused the request so. The connection is the
// clients' own (TLS with the client certificate, or plain), opened for this request alone. With r.halfClose it closes
// its side once the request is written (closeWrite).
// clients' own (TLS with the client certificate, or plain), opened for this request alone, and plain with r.plain. With
// r.halfClose it closes its side once the request is written (closeWrite).
func (w *world) sendRaw(r request) result {
if r.pause != 0 && (r.proto != "http/1.1" || !r.unframed) {
// A pause inside any other body is a mistake in the scenario data, which panics, as send does.
Expand All @@ -38,9 +38,18 @@ func (w *world) sendRaw(r request) result {
if r.then != "" && (r.proto != "http/1.1" || !r.unframed || r.pause != 0 || r.halfClose) {
panic(fmt.Sprintf("the battery sends a second request after an unframed http/1.1 body with no pause or half-close only, not %+v", r))
}
if r.plain && (r.proto != "http/1.1" || w.plain) {
panic(fmt.Sprintf("the battery sends plain HTTP over http/1.1 to a listener with tls only, not %+v", r))
}
start := time.Now()
fail := func(err error) result { return result{err: err, elapsed: time.Since(start)} }
conn, err := w.dialRaw(r.proto, serverNameFor(r))
var conn net.Conn
var err error
if r.plain {
conn, err = (&net.Dialer{Timeout: 20 * time.Second}).Dial("tcp", w.listener)
} else {
conn, err = w.dialRaw(r.proto, serverNameFor(r))
}
if err != nil {
return fail(err)
}
Expand Down
3 changes: 3 additions & 0 deletions conformance/scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ type request struct {
// scheme, on a raw h2 request, is the :scheme sent in place of the connection's own, https with tls and http
// without, as a client in front may send one that differs from the connection it uses.
scheme string
// plain, on a raw http/1.1 request to a file with tls, opens the connection with no TLS, as a client does that
// writes http:// for the TLS port.
plain bool
// then, on a raw unframed http/1.1 request, is a second request written on the same connection right after the
// body, in the same write, as a client that reuses its connection sends its next request: the answer compared is
// the second's, and the first's status is answer.first. A proxy that answers the first without reading its body
Expand Down
Loading